string - C++ simple sizeof difference between char array and char pointer -


char * test = "test"; cout << sizeof(test);   char test2[] = "test"; cout << sizeof(test2); 

running on visual studio 2010, why output 45?
shouldn't test string literal , sizeof string literal number of character elements in string literal including terminating null character?

test pointer string literal, not string literal (a char[]):

  • the sizeof(char*) 4, relating test
  • the sizeof(char[5]) 5, relating test2[]

hence 45 output.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -