Monday, 14 November 2016

Variables in C/C++

Variable:
Variable is nothing itself. It is actually name of memory location that our program can manipulate. In C language every variable specified by type which determine the size and layout of variable. These are called data types. such as:
char
int
float
double
void


Variable Declaration:
Variable declaration means defining variable in C language. We define variable declaration by using data type and variable name.
Syntax:
datatype variable name;
Example:
int num;
char name;
float salary;



Variable Initialization:
Variable initialization mean assigning value to variable. The syntax of variable initialization is given below:
Syntax:
datatype   variable name   value;
Example:
int num=1;
char name=a;
float num=2;

Rules for Naming Variable:
  • First letter of variable name is must be alphabet
  • The length of variable name is 39.
  • Underscore is used in variable name.
  • C is case sensitive language i.e. Upper and Lower case means variable names NUMBER and variable name number both are different variables.
  • Spaces are not alllowed in variable name.


2 comments: