+ 3

If I initiate arr[5] and assign a value to arr[6], is there a possibility I mess up other program?

In following code: ---CodeBegin--- #include <iostream> #include <string> using namespace std; int main() { int x,arr[5] = {00,11,22,33,44}; for(x=0;x<7;x++) { cout << arr[x] << endl; } return 0; } ---CodeEnd--- ---OutputBegin--- 0 11 22 33 44 5 65 ---OutputEnd--- Here I completely understand my index for arr ends at [4]. My question is would arr[7] = {100}; mess up other programs memory? Just curious.

18th Aug 2017, 4:32 AM
S_D
S_D - avatar
4 Respuestas
+ 6
The program would most likely crash on desktop, because you are accessing restricted memory which isn't allocated. https://stackoverflow.com/questions/1239938/accessing-an-array-out-of-bounds-gives-no-error-why
18th Aug 2017, 6:41 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
No, each process has its own virtual memory. You cannot access the memory of another process unless you get the kernel to do it for you with sys calls, or you access physical memory, which is only possible if you have ring0 access.
18th Aug 2017, 6:59 AM
aklex
aklex - avatar
0
That won't happened,because you can't pass the compiler ,it would throw error message.
4th Sep 2017, 4:20 PM
Ran
Ran - avatar