K
Keith Thompson
int main () {
typedef int array[5] = {1, 2, 3, 5 , 6};
array *ptr;
for (int i = 0; i < 5; ++i) {
printf ("%d", *ptr);
++ptr;
}
return 0;
}
why this is not operating .... as you said it is the pointer to the
array of 5 int.
It's "not operating" because it's not legal C, so it doesn't compile
in the first place.
You posted a chunk of code, but you didn't tell us what problem you
were having with it, or what you were trying to accomplish.
If you're asking why your compiler rejected the third line of your
program, please say so, and show us the error message, *and* tell us
what you're trying to accomplish.
Jens Toerring has made some suggestions. In addition, it looks like
you're trying to declare ptr as a pointer to an array, not as a
pointer to an int. That's almost certainly not what you should be
doing. Based on what you're trying to do in the loop, you want ptr to
be a pointer to int, so that *ptr is an int (which you can print with
"%d"), and so that incrementing it steps through the elements of your
array. If ptr is a pointer to an array of 5 ints, incrementing it
causes it step 5 ints at a time.