C++: We all know that a const variable needs to be initialized at the time of declaration.
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
#include <iostream.h>
void main( )
{
const char *p ;
p = "A const pointer" ;
cout << p ;
}
The output of the above program is 'A const pointer'.
This is because in this program p is declared as 'const char*' which means that the value stored at p will be constant and not p and so the program works properly.




Comments
Log in or create a user account to comment.