I was told to compile the following to see what errors the compiler gives when you try to compile a program that goes past the upper bound of an array. However codeblocks did not give me any errors. Now my question is if it is possible for codeblocks to do this by changing something in it's setting?
Code:
#include <iostream>
using namespace std;
int main()
{
long TargetArray[25]; // Array to fill
int i;
for (i = 0; i < 25; i++)
TargetArray[i] = 10;
cout << "Test 1: \n"; // test current values, should be 0
cout << "TargetArray[0]: " << TargetArray[0] << endl; //lower bound
cout << "TargetArray[24]: " << TargetArray[24] << endl << endl; // upper bound
cout << "\nAttempting at assigning values beyond the upper bound...";
for (i = 0; i <= 25; i++) // going a little to far
TargetArray[i] = 20; // asigning my fail for element 25
cout << "Test 2: \n";
cout << "TargetArray[0]: " << TargetArray[0] << endl;
cout << "TargetArray[24]: " << TargetArray[24] << endl;
cout << "TargetArray[25]: " << TargetArray[25] << endl; //out of bounds
return 0;
}