From: Tsu <ts...@cy...> - 2004-04-28 06:20:21
|
> #include <iostream> > int main() { > char* one =3D "oneone"; > char two[] =3D "twotwo"; > cout << sizeof( one) << endl; > cout << sizeof( two) << endl; > cout << strlen( one) << endl; > cout << strlen( two) << endl; > } > ----- output ----- > 4 > 7 > 6 > 6 > Ok, question --- My assumption forever has been that one and two are bot= h > char* or pointers to a char. > =09What's wrong with my thinking? > =09I was expecting sizeof( one) and sizeof( two) to both return 4, the > =09actual size of a pointer, 4 bytes. Instead sizeof( two) returnes the > =09number of chars in the array including the null terminator. I'm > =09cornfused. I'm far from being an expert but I think that 'one' is a pointer (thus the= 4 bytes) to the const literal (I suppose this is the correct term) "oneon= e" and the other is an array of 7 char positions ("twotwo" + '\0'). ~/gnf.pt |