Skip to main content

Interpret pointer declarations

Short answer

i) p is a pointer to int. ii) p is a function taking char* returning int. iii) p is a function taking char* returning int*. iv) p is a function taking void returning int*. v) p is an array of 10 pointers to functions taking char returning int*.

Define following term: i) intp; ii) int p(chara) iii) int(p(chara)) iv) int p(void) v) int(*p[10])char a)

(The last declaration is written as int *(*p[10])(char a), assuming the missing brackets.)

DeclarationMeaning
i) int *p;p is a pointer to an integer
ii) int p(char *a)p is a function taking a pointer to char and returning an int
iii) int (*p(char *a))The brackets are redundant: same as int *p(char *a). p is a function taking a pointer to char and returning a pointer to int
iv) int *p(void)p is a function with no arguments returning a pointer to int
v) int *(*p[10])(char a)p is an array of 10 pointers to functions, each taking a char and returning a pointer to int

How to read: start at the name, go right ([] or ()), then left (*), and use brackets to change the order. For (v): p[10] is an array of 10, * makes them pointers, (char a) makes them pointers to functions, and int * is the return type.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 9 questions →