new student something puzzle about a pointer;
As I learned from books, before using a pointer, it must be initialized, so we usually use this as
int a = 12;
int * p = &a;
therefore, I understand why it is int* p = 12wrong, because it does not have an address;
then I find something today during coding, i.e. from this:
char * months[12] = {"Jan", "Feb", "Mar", "April", "May" , "Jun", "Jul"
,"Aug","Sep","Oct","Nov","Dec"};
Then another commonly used situation occurred to me. It:
char *p = "string"; (this is ok , why int * a = 12 can't be allowed ?)
I am puzzled. when is it initialized and how? and why int * a = 12can not be automatically initialized? maybe something about memory location.
source
share