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, relatingtest - the
sizeof(char[5])5, relatingtest2[]
hence 45 output.
Comments
Post a Comment