I recently re-started learning C and well decided to conquer what put me off last time: pointers! So I'm experimenting with strings and pointers to see how things react and finally wrap my brain around the beast.
Now I declared a char string[256]
that I am later iterating through using a pointer (code block at the end of the post). I have "declared" but not "initialised" (I'm very proud to know the difference!) the string so I can see what data lies in the memory that the string points to.
When I run the program, the output is obviously gibberish of mixed ascii characters / question marks that, I imagine, indicate binary data. All is well!
BUT
(TLDR; marker:) I notice that I get surprisingly little gibberish so I try to reduce the size of my char array to see when weird stuff starts to appear and there is a very clear threshold at 249 characters. Any value below that returns an empty line.
Why is this? Why 249 characters? Is it just that there is no program using this part of the RAM at the moment or is there a more intricate explanation?
int main(void){
char string[248];
for (const char *c = string; *c; c++) {
printf("%c", *c);
}
}