Differences between declaration and initialization in C/C++
Simple definition of declaration and initialization in C/C++. Both are same in C and C++.
Declaration: A declaration is a statement in C and C++ that says " Here is the name of variable and type of the variable". i am not telling you anything more about it.
[code]
Initialization: Initialization is definition where variable is also given a value. Some languages automatically initialize a value to all variable such as 0 and some language don't initialize.
Declaration: A declaration is a statement in C and C++ that says " Here is the name of variable and type of the variable". i am not telling you anything more about it.
[code]
int a; // declaration of a integer int *p; // declaration of pointer to integer char ch; // declaration of character char *ptr; //declaration of pointer to character int fun(int); //declaration of function struct add; //declaration of structure[/code]
Initialization: Initialization is definition where variable is also given a value. Some languages automatically initialize a value to all variable such as 0 and some language don't initialize.
int a //declaration of integer variable a=10 //initialization of integer variable int b=10 //declaration and initialization of integer variable int *p=&a //declaration and initialization of pointer to integer char ch //declaration of pointer to character ch='c' //initialization of character variable char *ptr //declaration of pointer to character variable ptr=&ch //initialization of pointer to character variable