Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Variables in C++ Program

Rating
-
Sold
-
Pages
3
Uploaded on
28-10-2021
Written in
2020/2021

Learn about the concepts of Variables in C++ Program. View in full!

Institution
Course

Content preview

VARIABLES IN C++

A variable is a name which is associated with a value that can be changed. For example when I write
int num=20; here variable name is num which is associated with value 20, int is a data type that
represents that this variable can hold integer values.

Syntax of declaring a variable in C++
data_type

For example:
int num1=20, num2=100;

We can also write it like this:
int num1,num2;
num1=20;
num2=100;


TYPES OF VARIABLES
Variables can be categorized based on their data type. For example, in the above example we have seen
integer type variables. Following are the types of variables available in C++.

int: These type of variables holds integer value.

char: holds character value like ‘c’, ‘F’, ‘B’, ‘p’, ‘q’ etc.

bool: holds boolean value true or false.

double: double-precision floating point value.

float: Single-precision floating point value.


TYPES OF VARIABLES BASED ON THEIR SCOPE
Before going further let’s discuss what is scope first. When we discussed the Hello World Program, we
have seen the curly braces in the program like this:




Any variable declared inside these curly braces have scope limited
int main { within these curly braces, if you declare a variable in main() functionand
try to use that variable outside main() function then you will get
//Some code compilation error.
}


Now that we have understood what is scope. Let’s move on to the types of variables based on the scope.
These are the:

Written for

Institution
Course

Document information

Uploaded on
October 28, 2021
Number of pages
3
Written in
2020/2021
Type
Class notes
Professor(s)
Nani madriaga
Contains
All classes

Subjects

$4.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sophiamadriaga

Get to know the seller

Seller avatar
sophiamadriaga
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
9
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions