if i am declaring an array of let say size 5 and if i take input size 7
then why my array is taking elements till 7 as size declared is 5 only
Array input elements
@Namanjain123
This is very risky as it may work sometimes or it may give a runtime error some other times. It is also possible that it may corrupt some other data of your program.
When we declare an array of size 5 , memory of 5 blocks is allocated to us. Since the array variable is actually a constant pointer only , you can still access the blocks which exist outside the allocated chunk of memory however this is very risky. Its possible that the other part may belong to some other variable in your code and when you change the value in that block of memory , you might end up corrupting the data of some other variable in your code. Some compilers throw a runtime error in this case however that is not certain. In general , avoid doing that.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.