hi
i'm trying to understand how to use new and while i was experimenting I came accross something i dont understand...
here is a quick example:
Code:
int main()
{
int* var1;
int* var2;
var1 = new int[1];
var2 = new int[1];
var1[1] = 2;
var2[100] = 3;
var1[100] = 3;
printf("var1[1] = %d, var2[100] = %d\n", var1[1], var2[100]);
printf("var1[100] = %d\n", var1[100]);
return 0;
}
why does the compiler let me give var1 and var2 values at array index 100 if I only made a new integer the size of 2 array indexes ([1])? I thought the "new" was like calling malloc just a little nicer
here is the output f the program aswell
var1[1] = 2, var2[100] = 3
var1[100] = 3
Press any key to continue
whats even more weird is that its actually being set to the right values 1 even tho i didnt allow that much space memory to be used when i used new!!!...now I really don get it..
thanx for your help in advance,
Boomba