I am writing a C program, which has a 5-element array to store a string. And I am using gets()
to get input. When I typed in more than 5 characters and then output the string, it just gave me all the characters I typed in. I know the string is terminated by a \0
so even I exceeded my array, it will still output the whole thing.
But what I am curious is where exactly gets()
stores input, either buffer or just directly goes to my array?
What if I type in a long long string, will gets()
try to store characters in the memories that should not be touched? Would it gives me a segment fault?