I test the length/size of char array, pointer and string as below code.
Why sizeof(pArray) is 8? I guess it is a pointer which should be 4.
Why sizeof(str) is 8 instead of 6 or 7?
Why sizeof("abcdef") is 7 instead of 6?
char array1[10] = {'a', 'b'};
char array[10] = "abcdef";
const char * pArray = "abcdef";
string str = "abcdef";
printf("array1:%d, array:%d, pArray:%d, str:%d,strsize:%d, strlen:%d, raw:%d\n", sizeof(array1), sizeof(array), sizeof(pArray), sizeof(str), str.size(), str.length(), sizeof("abcdef"));
Program output:
array1:10, array:10, pArray:8, str:8,strsize:6, strlen:6, raw:7
string? Is it just a typedef ofchar*? Anyway, pointers can be 8 bytes too (this is probably a 64-bit environment).