0

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

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.

4
  • You will learn about pointers and the type definitions later on. – ChrisG Jul 1 '15 at 9:14
  • Got it ! Thanks ! – Gautam Sharma Jul 1 '15 at 9:22
  • 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 code string str; string *strp = NULL; printf("\n\nCS50's string %lu bytes\n", sizeof(str)); printf("CS50's string pointer %lu bytes\n", sizeof(strp)); – Wesley Gonçalves May 21 '18 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 – Wesley Gonçalves May 21 '18 at 23:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .