A
Angus
I have this array:
char* s[] = {"cat", "cat", "dog", "mouse", "rat"};
int sz = sizeof(s); // 20 why 20???
I would expect sizeof to report 17. Why is it reporting 20?
to work out the number of elements works ok:
sz = sizeof(char*); // 4 - (size of a pointer)
sz = sizeof(s) / sizeof(char*); // 5 (correct)
I suppose if sizeof(s) had returned 17 then the calculation of the no.
of elements would not be correct. But I would be interested to know
how the array takes up 20 (bytes?)?
Angus
char* s[] = {"cat", "cat", "dog", "mouse", "rat"};
int sz = sizeof(s); // 20 why 20???
I would expect sizeof to report 17. Why is it reporting 20?
to work out the number of elements works ok:
sz = sizeof(char*); // 4 - (size of a pointer)
sz = sizeof(s) / sizeof(char*); // 5 (correct)
I suppose if sizeof(s) had returned 17 then the calculation of the no.
of elements would not be correct. But I would be interested to know
how the array takes up 20 (bytes?)?
Angus