I am new to CS50 and teaching AP Comp Sci Principles for the first time this school year. One of my students asked it there was a limit to the amount of bits get_string() can store. I wasn't sure what to tell him...

I know there are limitations to int and float (32 bits) unless you use unsigned, double, and long long but I was stumped on the string question. Thanks!


That one's probably limited only by the memory it can allocate in a contiguous chunk. On the cs50.io machines, with 512MB of RAM plus swap, that might be a hundred million characters, something around that. But interesting thought, haven't tried.

PS: You can find the source of get_string in https://github.com/cs50/libcs50/blob/master/src/cs50.c (basically: uses realloc a lot, increasing buffer size by factor 2 and shrinking down later)


we can think that get_string () is equivalent to char *, we can use dynamic memory storage

char* name = malloc(memory we need)

although the get_string () function handles memory somewhat differently, it is essentially the same. In short there is no explicit limit for memory storage more than the limitations of our system

You must log in to answer this question.

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