Hi,
what happens if we allocate more than MAX_SIZE in below situation. Is the result unpredictable??
How is this related to corrupting "const" declarations??
Are they(malloc and const) both allocated from heap???
Thanks,
Tharakan.
const int p=100; <-- can a malloc like below corrupt a const declaration ???
{
int MAX_SIZE=10;
int *inptr[MAX_SIZE];
intptr[0] = alloc_and_set();
intptr[1] = alloc_and_set();
:
:
:
inptr[9] = alloc_and_set(); <-- reaches MAX_SIZE???
inptr[10] = alloc_and_set(); <-- Is this valid???
inptr[11] = alloc_and_set(); <-- Is this valid???
inptr[12] = alloc_and_set(); <-- Is this valid???
inptr[13] = alloc_and_set(); <-- Is this valid???
inptr[14] = alloc_and_set(); <-- Is this valid???
}
int * alloc_and_set(){
int *t;
t= (int*) malloc(sizeof(int));
*t = 10;
return t;
}
}