The *
character in C language is not a simple decoration. It declares a pointer that has to point to something. Here you declared an array of two pointers, but never initialized the pointer themselves. And dereferencing an uninitialized pointer is explicitely Undefined Behaviour (the hell for C programmers). If you want to process integers, get rid of the pointers:
int as[2];
for(i=0;i<2;i++)
{
as[i]=i;
printf("%d\n",as[i]);
}
Or if you really want to process pointers, ensure that they are initialized to point to a valid object:
int *as[2];
int data[2]
for(i=0;i<2;i++)
{
as[i] = &(data[i]); // Ok, as[i] now points to a valid integer
*as[i]=i;
printf("%d\n",*as[i]);
}
BTW, the idiomatic way to get the address of an element of an array would be:
as[i] = data + i;