Char array capacity | Sololearn: Learn to code for FREE!


Char array capacity

I've just tried to enter more characters than I set for char array in C ex) code: char a[9]; input: this definitely is more than 9 characters But it still works! Why is it?

10/15/2019 8:16:41 AM


1 Answer

New Answer


Because C lets you do it by not checking the bounds of your array. It's a very simple tradeoff, less security for more speed. What actually happens is called undefined behaviour, i.e. the outcome is compiler-specific, but C does not guarantee for anything here; it might work, it might seem to be working but is actually corrupted, it might crash, everything might be on fire, etc. etc., you get what I mean. For more reference, see the following questions: