wrote:
> I am able to initialize the pointer to the array as
> int (*a)[10];
> int b[100];
> a = &b[0];
> But i am getting the warning
> warning: assignment from incompatible pointer type
Of course you are. a is a pointer to an array of 10 ints (which
you probably do not need), while &b[0] is a pointer to an int. Your
compiler is doing you a favor.
> My Code is
> int main()
int main( void ) /* better */
> {
> int (*a)[10];
> int b[100];
> int i;
> for(i=0;i<100;i++)
for( i=0; i < sizeof b; i++) /* better */
> b[i]=i;
> a = &b[0];
Wrong, as I said.
> printf(" %u %u %d %d\n",a ,&b[0],**a,b[0]);
Wrong in multiple ways:
1) You did not include <stdio.h>.
2) %u is not the conversion specifier you want for pointers.
printf( " %p %p %d %d\n", (void*)a, (void*)&b[0], **a, b[0] );
Note the casts; they are required.
> a++;
> printf(" %u %u %d %d\n",a ,&b[10],**a,b[10]);
> a++;
> printf(" %u %u %d %d\n",a , &b[20],**a,b[20]);
> a++;
> printf(" %u %u %d %d\n",a , &b[30],**a,b[30]);
Unless you are using a C99 compiler, you must return a value from
main(). Your compiler should have warned you about this unfortunate
omission.
> }
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.