E
erktek
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int i;
int a[1];
int *p = NULL;
p = a;
p = (int *) realloc(p,3*sizeof(int)); // here the code crashes ?
p[0] = 1;
p[1] = 2;
p[2] = 3;
for (i=0; i < 3;i++)
printf("%d\n",p);
free(p);
return 0;
}
The code above crashes ? What is the reason ?
Isn't it possible to reallocate the array "a" again via pointer p ?
#include <string.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int i;
int a[1];
int *p = NULL;
p = a;
p = (int *) realloc(p,3*sizeof(int)); // here the code crashes ?
p[0] = 1;
p[1] = 2;
p[2] = 3;
for (i=0; i < 3;i++)
printf("%d\n",p);
free(p);
return 0;
}
The code above crashes ? What is the reason ?
Isn't it possible to reallocate the array "a" again via pointer p ?