D
dave
From the FAQ:
1.32: What is the difference between char a[] = "string"; and
char *p = "string"; ?
A: The first declares an initialized and modifiable array; the
second declares a pointer initialized to a not-necessarily-
modifiable constant string.
I have this code in gcc (yes, it's C++, but it is a C question):
char * char_ptr = "stringthingy";
cout << "Size of char_ptr is " << sizeof(char_ptr) << "\n\n";
cout << "*char_ptr = " << *char_ptr << "\n";
cout << "char_ptr = " << char_ptr << "\n";
And this is the result:
Size of char_ptr is 4
*char_ptr = s
char_ptr = stringthingy
So sizeof() returns 4 as expected and the dereferenced pointer
returns 's' as expected. But why isn't an address returned for
the non-dereferenced pointer? If "stringthingy" is correct, why
doesn't sizeof() return 13?
I am confused!
TIA,
~Dave~
1.32: What is the difference between char a[] = "string"; and
char *p = "string"; ?
A: The first declares an initialized and modifiable array; the
second declares a pointer initialized to a not-necessarily-
modifiable constant string.
I have this code in gcc (yes, it's C++, but it is a C question):
char * char_ptr = "stringthingy";
cout << "Size of char_ptr is " << sizeof(char_ptr) << "\n\n";
cout << "*char_ptr = " << *char_ptr << "\n";
cout << "char_ptr = " << char_ptr << "\n";
And this is the result:
Size of char_ptr is 4
*char_ptr = s
char_ptr = stringthingy
So sizeof() returns 4 as expected and the dereferenced pointer
returns 's' as expected. But why isn't an address returned for
the non-dereferenced pointer? If "stringthingy" is correct, why
doesn't sizeof() return 13?
I am confused!
TIA,
~Dave~