out of array index? | Sololearn: Learn to code for FREE!

+1

out of array index?

https://code.sololearn.com/cq4xACSzkEId/?ref=app whay this happened?(whay arr[2] is anonymous Integer?) and other question is: is there runtime error in c++?

4/16/2021 8:21:23 PM

Mehran

19 Answers

New Answer

+2

In c++ imagine array saved in memory one by one and there isnt any alert if you get out of array index it just continue reading the memory so you need be careful with this

+2

Mostly just in memory alocated for this process, so you cant crash your system or apps

+2

It can be whatever like another piece of your code or also just garbage, probably not big meaning

+2

Martin Taylor thanks it was useful for me.

+1

David Dolejší Can pointers access to any place of memory?

+1

David Dolejší wich apps stored that Integer on this index?

+1

David Dolejší i I realized that one index after array length is always zero. (test code) why?

+1

How many times did u try it? I m not expert so dunno, u can try save another value and I m sure it will work

+1

Martin Taylor are you see my code? i know character array end by null. my code: int arr[]={2,1}; cout<<arr[2]<<endl;//Same as *(a+2). result is anonymous Integer and arr[3] is 0 or 1 depends on compiler that i check. why?

+1

Martin Taylor answer another my question about c++ (see my activity)

+1

Martin Taylor it is my another question : using c++ language? i love c/c++ because it is very self-description(concepts describe themselves with computer architecture) and powerful. But it no longer has much use in the world, in Windows c#(Microsoft offers c#) is used on Android java, and on the web the client uses JavaScripit and etc, If I learn it, I will forget it because I have no use. What your offer? when I mention you, are you get notification?

+1

ok it is beautiful. second variable use memory cell after array because that declared after it.

+1

Martin Taylor change code with it int arr[] ={1,2}; int a=3 int b=4; cout <<arr[2]<<endl ; cout <<arr[3]<<endl ; //result is 4, 3 why? are data transfer in memory?

+1

these tests depend on compiler.