Pointers to arrays in C

dietz%slb-doll.csnet at CSNET-RELAY.ARPA dietz%slb-doll.csnet at CSNET-RELAY.ARPA
Sat Apr 5 14:03:37 AEST 1986


>>	    int (*x)[10];
>
>That is not a pointer to an array.  It is an array of pointers to ints.
>	George Tomasevich, ihnp4!twitch!grt
>	AT&T Bell Laboratories, Holmdel, NJ

It *is* a pointer to an array.  Try running this program:

    main()
    {
	char (*x)[10];
	printf("%d\n%d\n%d\n", sizeof(*x), sizeof(x), sizeof((*x)[2]));
    }

It prints (on a VAX running ULTRIX):

10
4
1

So, *x is an object of size 10 (the array), x is an object of size 4 (a
pointer), and (*x)[2] is a single byte (a char).  C's strange type
syntax strikes again.

Paul Dietz
dietz at slb-doll.csnet



More information about the Comp.lang.c mailing list