C++ Variable, Declaration and Initialization of Variable


Variable in C++

Variables are used to store values. variable name is the name of memory location where value is stored. It must be alphanumeric, olny underscore is allowed in a variable name. It is composed of letters, digits and only underscore. It must begin with alphabet or underscore. It can not be begin with numeric.

Declaration of Variable

Declaration will allocate memory for specified variable with garbage value.

Syntax :

		Data-Type Variable-name;  

Examples :

		int a;
		float b;
		char c;

Initialization of Variable

Initialization means assigning value to declared variable. Every value will overwrite the previous value.

Examples :

		 a = 10;
		 b = 4.5;
		 c = 'a';

Character value must be enclosed with single quotes.

		a = 4.5; 

if we assign decimal value to integer variable, it will accept only integer portion of value. In the above example variable a will accept 4 only.

Related topics