C declarations

Arnold Robbins arnold at gatech.UUCP
Thu Jan 31 03:23:29 AEST 1985


Morris M. Keesan {decvax,linus,ihnp4,wivax,wjh12,ima}!bbncca!keesan writes:
> 
>	[.....]
> 	int *ptr[];            /* ptr is a pointer to an array of int */
>	[.....]
>

Sorry, but this declaration means ptr is an array of pointers to ints (similar
to the char *argv[] declaration of argv).

A pointer to an array of ints would be

	int array[] = { 1, 2, 3 };
	int *ptr = & array[0];	/* just use a simple pointer */
	/* or int *ptr = array; but that is what started this whole mess */

since there is no difference between pointing to a single int, or the first
element in an array.

I heartily agree that pointers and array are probably the most confusing
aspect of C.
-- 
Arnold Robbins
CSNET:	arnold at gatech	ARPA:	arnold%gatech.csnet at csnet-relay.arpa
UUCP:	{ akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold

Help advance the state of Computer Science: Nuke a PR1ME today!



More information about the Comp.lang.c mailing list