C++ language

Previous Home Next

A variable is the temporary storage space in memory stored by its value. variable can be represented by their name,

The variable name can be any think like set of one or more letters, digits or underscore

Rules for defining variable name

  • A variable name can have set of letters or digits or underscore
  • A variable name can't have White space, punctuation symbols or other characters .
  • A variable name must begin with a letter.
  • Keywords or any reserved words cannot be of variable names.
  • Variable names written in capital letters and small letters are different variable because C++ is a case-sensitive language

Declaration of variables.

before declaring a variable first should think about data type of variable and also the name of the variable .Name of the variable should have some meaning .Data type in C++ is as:

data_type  variable_name;

short int: used to represent short integer.

int: used to represent integer.

long int: used to represent long integer.

float: used to represent floating point number.

double: used to represent double precision floating point number.

long double: used to represent double precision floating point number.

char: used to represent a single character.

bool: used to represent two values: True or False.

Type Size Values
unsigned short int 2 bytes 0 to 65,535
short int 2 bytes –32,768 to 32,767
unsigned long int 4 bytes 0 to 4,294,967,295
long int 4 bytes –2,147,483,648 to 2,147,483,647
int 4 bytes –2,147,483,648 to 2,147,483,647
unsigned int 4 bytes 0 to 4,294,967,295
char 1 byte character values
bool 1 byte true or false
float 4 bytes 1.2e–38 to 3.4e38
double 8 bytes 2.2e–308 to 1.8e3
 #include <iostream>	//include header file
  using namespace Beg;
 int main()		//main function with int return type
	  int a;	// declaration
	  int sum=0;
	   // declaration
	  cin>> a;	//object of in stream
   	cout << "value of a is.\n"
	,a;	//object of output stream
	sum= sum+a;
	 cout << "sum is.\n"
	 ,sum;		//object of output stream
	return 0;//return function

value of a.10
sum is.10

Reference Variable: A reference variable provide an alias (alternative name) for a previously defined variable name.

data_type & reference_name = variable_name;

Previous Home Next