+ 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.
4 Answers
+ 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
+ 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.
0
That won't happened,because you can't pass the compiler ,it would throw error message.