Here is a code 1
int j[2];
int *ptr = j;
for(int i=0;i<__INT_MAX__;++i){
cout << i << endl;
j[i]=0;
}
In this code, it prints 1 2 3 4 5 6 7 and again 1 2 3 4 5 6 7. It doesn't give segmentation fault. But when I assign array's adress to pointer and write ptr[i] instead of j[i], it prints 1 2 3 4 5 6 and it gives segmentation fault. That code:
int j[2];
int *ptr = j;
for(int i=0;i<__INT_MAX__;++i){
cout << i << endl;
ptr[i]=0;
}
So I think Netbeans handle the situation, but this is harmful for programmer. How can I disable it? Are there other "protections" like this?
Summary edit: It must give me segmentation fault but it is not. I want to get fault, so I'll be able to fix my code. Netbeans prevent that error.
Edit 2: This topic isn't duplicated. In that topic, he try just one address up. In my code, there is infinite loop and it must give seg fault
Addition 3: When I allocate from heap, give pointer that adress and put in to loop, i value is approaching 30.000's. But in first code, it increases until 6-7, again starts from 0. Because of this, I think my IDE prevent seg fault.