avr39-ripe

Array index out of range corrupts variable

Feb 27th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     const int n = 10;
  9.     int test = 2607;
  10.     int test1 = -1;
  11.     int a[n] = { 0 };
  12.  
  13.     cout << "&test=" << &test << " &imin=" << &test1 << endl;
  14.     cout << "&a[0]=" << &a[0] << " &a[n-1]=" << &a[n - 1] << endl;
  15.     cout << "&a[n-1+5]=" << &a[n - 1 + 6] << endl;
  16.     cout << "VALUE: test=" << test << endl;
  17.     cout << "VALUE: a[n-1+6]=" << a[n - 1 + 6] << endl;
  18.     a[n - 1 + 6] = 3040;
  19.     cout << "VALUE: test=" << test << endl;
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment