Char array capacity | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite

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?

15th Oct 2019, 8:16 AM
SangMinCNSA - avatar
1 Réponse
+ 2
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:
15th Oct 2019, 9:07 AM
Shadow - avatar