+ 1

Lets say i create array like a[5] which means size of array is 5 ohk

but when i start entering elements like size of array is 5 but in for loop i put value from i = 1 to i= n where i say n is any size i can enter from my side. now i enter n= 10 and the program will start taking 10 values. now my question is how this is possible??? i created array of memory space 5 but i can specify the size to be even 10 or more and its working perfectly?? just how?

13th Sep 2018, 3:30 PM
Bunny
Bunny - avatar
3 Answers
+ 2
It may work to some extent only, but I would strongly suggest you not to rely on such things. In that event, the program writes the extra 5 values outside the boundaries of the memory allocated by system for the array, now, we don't know whether the 5 extra slots were actually free or used by other applications, or even the system itself, and eventually, that can trigger access violation (for writing in some other applications' memory space). And not to mention, it was not a good programming habit, a good coder must avoid such things : ) Hth, cmiiw
13th Sep 2018, 4:02 PM
Ipang
+ 1
thnx
13th Sep 2018, 5:04 PM
Bunny
Bunny - avatar
+ 1
You're welcome : )
13th Sep 2018, 5:06 PM
Ipang