The data type string in cs50.h is of size 4 bytes. Then how come it can take a string of size > 4. Is that data type extendable ( does it extend in size according to the string we pass on to it) and by default is it 4 bytes?
1 Answer
The string type is just a defined type of char* (a char pointer) which since it is a pointer has a size of 4 bytes.
-
-
-
There's some time since the question but pointers are actually 8 bytes in size independently of its type. You can check it with this Gist. And to check the CS50
string
type, you can check with this lines of codestring str; string *strp = NULL; printf("\n\nCS50's string %lu bytes\n", sizeof(str)); printf("CS50's string pointer %lu bytes\n", sizeof(strp));
May 21, 2018 at 22:04 -
Apparently the right answers is "it depends" as explained by Greg Kemnitz in this Quora question quora.com/What-is-the-size-of-a-pointer-in-C May 21, 2018 at 23:13