+ 1

I have allocated space only for 3 characters. But y I could print more than 3

char a[3]; gets (a) ; printf ("%s", a) ;

3rd Dec 2018, 9:06 AM
Mohamed Burhan
Mohamed Burhan - avatar
3 Answers
+ 4
This array gives contigous memory of 3 but it is still possible that a[3] which is the memory location just after a[2] is available so you are able to use it. Conclusion: It is a matter of chance that a[3], a[4], a[5] etc. can be used by your code.
3rd Dec 2018, 9:55 AM
Lakshay
Lakshay - avatar
+ 1
Thanks got you all😊👍
3rd Dec 2018, 10:43 AM
Mohamed Burhan
Mohamed Burhan - avatar