Pointer confusion -- forgot original title
David Herron, NPR Lover
david at ukma.UUCP
Fri Feb 8 13:46:00 AEST 1985
In article <11807 at gatech.UUCP>arnold at gatech.UUCP (Arnold Robbins) writes:
>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 */
...
>I heartily agree that pointers and array are probably the most confusing
>aspect of C.
Sorry, you are wrong. A "int **ptr" would be an array of pointers to int.
(The array (in this case) the array is of indeterminate length). Another
way of declaring this is "int *(ptr[<length>])".
In general it is best to help out your compiler whenever possible
by parenthesizing constructs. But in C, the parenthesizing gets
slightly confusing when declaring arrays of pointers to functions.
(BTW, the original declaration above was an array of pointers).
>Help advance the state of Computer Science: Nuke a PR1ME today!
Hey! At least you have some sense about you! :-) :-) :-) :-)
--
-:--:-
David Herron;
ARPA-> "ukma!david"@ANL-MCS or david%ukma.uucp at anl-mcs.arpa
UUCP-> {ucbvax,unmvax,boulder,research}!anlams!ukma!david
UUCP-> {mcvax!qtlon,vax135,mddc}!qusavx!ukma!david
UUCP-> {A-Large-Portion-of-The-World}!cbosgd!ukma!david
No stupid sayings (I can't think of one).
No stupid disclaimers (Nobody else would claim my statements anyway).
More information about the Comp.lang.c
mailing list