What does int *p[10]; declare?
[] binds tighter than *, so p is first an array of 10, and each element is a pointer to int.
Complicated Declarations · Exercise 1 of 4
Twelve multiple-choice questions: decode declarations with pointers, arrays and functions, const placement and typedef. Pick an option to check your answer instantly.
What does int *p[10]; declare?
[] binds tighter than *, so p is first an array of 10, and each element is a pointer to int.
What does int (*p)[10]; declare?
The parentheses make p a pointer first; what it points to is an array of 10 int. p + 1 moves by 40 bytes.
What does int *f(void); declare?
() binds tighter than *, so f is a function; the * belongs to its return type. A pointer to a function needs int (*f)(void).
Which declares an array of 4 pointers to functions that take a double and return a double?
Read it: f is an array of 4 (f[4]), of pointers (*), to functions (double) returning double. Option A tries to make an array of functions, which C does not allow.
What is fp in char *(*fp)(const char *);?
(*fp) – pointer; (const char *) – to a function with that parameter; char * – returning a char pointer. strchr-like functions have this shape.
Which declares get as a function taking an int and returning a pointer to a function (void) returning int?
get(int) is the function; * makes its result a pointer; the outer (void) and int describe the function pointed to. With typedef int (*fn)(void); it becomes fn get(int);.
What does void (*signal(int sig, void (*func)(int)))(int); declare?
signal(...) is a function with two parameters; its result is used as (*result)(int), returning void – the previously installed handler.
With int *const p = &x;, which statement is allowed?
p is a constant pointer: it always points to x, but x can be modified through it. For const int *p it is the other way round.
Which pair of declarations means the same thing?
const qualifies the type next to it; before or after char makes no difference. Only a const after the * makes the pointer itself constant.
Which declaration is not allowed in C?
A function cannot return an array. Option A – a function returning a pointer to an array of 3 int – is legal.
Timed online tests with instant scores and explanations.