Sunday, 31 July 2016

HOW TO START A PROGRAM ?

               DECLARATION AND INITIALIZATION


Variable must be declared before they are used .usually it is preferred to declare them at the starting of the program,but in C++ they can be declared in the middle of program too,must be done before using them .

EXAMPLE:
  
int i;               //declared but not initialized
char c;
int i, j, k; n                   //multiple declaration

initialization means assigning value to an already declared variable,

int i;                        //declaration
i=20;                // initialization

initialization and declaration can be done in one single step also,

int i=20;                    // initialization and declaration in same step
int=20, j=56;

if a variable is declared and not initialized by default it will hold a garbage value also,if a variable is once declared and if try to declare it again ,we will get a compile time error.

int i,j;
i=20;
j=56;
int j=i+j;     // compile time error,cannot redeclare a variable in same scope


No comments:

Post a Comment