array loading and reading

I am having trouble getting an array to print, correctly, what is loaded. It gives me number's that are in the 1000's. ????

any help? Here is the text:

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

void main(void)

{
clrscr();
int I;
int g[3][3];
int opt;

for (I=0;I<=3;I++);
{
g[I][3]=1;
}

for (I=0;I<=3;I++)
{
opt=g[I][3];
cout<<opt<<" ";
}
}
Array size is 3. So index range is between 0 and 2.
To elaborate on shadow123's point,

declaring an array of size [4] allocates 4 places, and then a null terminator which tells your computer where the array ends. The places you store NUMBERS in are going to be 0 1 2 and 3, the final location, position 4, is permanently reserved for that terminator. Without it, your array would take up all the memory on your computer, and as such it can't be removed (that I know of). If you want an array that takes up any size you need, I'd recommend vectors and .pushback or std::strings
Programmers always count from 0. ;-)
Topic archived. No new replies allowed.