Skip to content
QuiznExam

Complicated Declarations in C

Test your knowledge of complicated C declarations, including pointers, arrays, functions, function pointers, pointer-to-pointer declarations, and the rules used to interpret complex declarations.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

const in C

15 questions · 12 min · Medium

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What does the declaration `int *p;` declare?

    • A. An integer variable
    • B. A pointer to an integer
    • C. An array of integers
    • D. A function returning an integer
    Show answer

    B. A pointer to an integer

    The `*` indicates that `p` is a pointer, and its pointed-to type is `int`.

  2. 2. What does the declaration `int **p;` mean?

    • A. A pointer to an integer
    • B. An integer pointer
    • C. A pointer to a pointer to an integer
    • D. An array of integer pointers
    Show answer

    C. A pointer to a pointer to an integer

    The two `*` operators indicate two levels of indirection: `p` points to a pointer that ultimately points to an integer.

  3. 3. What does the declaration `int *a[10];` declare?

    • A. A pointer to an array of 10 integers
    • B. An array of 10 pointers to integers
    • C. An array of 10 integers
    • D. A function returning an array
    Show answer

    B. An array of 10 pointers to integers

    The array subscript has higher precedence than `*`, so `a` is an array of 10 elements, with each element being a pointer to int.

  4. 4. What does the declaration `int (*p)[10];` declare?

    • A. An array of 10 integer pointers
    • B. A pointer to an array of 10 integers
    • C. A pointer to 10 integer variables
    • D. An array containing one pointer
    Show answer

    B. A pointer to an array of 10 integers

    The parentheses make `*p` bind together before the array subscript, so `p` is a pointer to an array of 10 integers.

  5. 5. What does `int (*fp)(int);` declare?

    • A. A function returning a pointer to int
    • B. A pointer to a function taking an int and returning int
    • C. A pointer to an integer
    • D. An array of function pointers
    Show answer

    B. A pointer to a function taking an int and returning int

    The parentheses around `*fp` make `fp` a pointer to a function. The function accepts an int and returns an int.

  6. 6. What does the declaration `int *f(void);` mean?

    • A. A pointer to a function returning void
    • B. A function taking no arguments and returning a pointer to int
    • C. A function returning an integer
    • D. A pointer to an integer function
    Show answer

    B. A function taking no arguments and returning a pointer to int

    Because `f(void)` is not parenthesized with `*f`, `f` is a function. Its return type is `int *`.

  7. 7. What does the declaration `int (*f(void))[10];` declare?

    • A. A function taking no arguments and returning a pointer to an array of 10 integers
    • B. A pointer to a function returning an array of 10 integers
    • C. An array of 10 function pointers
    • D. A function returning an integer pointer
    Show answer

    A. A function taking no arguments and returning a pointer to an array of 10 integers

    Starting at `f`, `f(void)` makes it a function with no parameters. The `*` indicates that it returns a pointer, and `[10]` specifies an array of 10 integers.

  8. 8. What does `int (*a[5])(double);` declare?

    • A. A pointer to an array of five functions
    • B. An array of five pointers to functions taking double and returning int
    • C. A function returning an array of five pointers
    • D. An array of five double pointers
    Show answer

    B. An array of five pointers to functions taking double and returning int

    The `[5]` makes `a` an array of five elements, and each element is a pointer to a function accepting a double and returning int.

  9. 9. Which operator generally has higher precedence when interpreting a C declaration?

    • A. Array subscripting `[]`
    • B. Pointer declarator `*`
    • C. Both always have equal precedence
    • D. The comma operator
    Show answer

    A. Array subscripting `[]`

    In declarators, postfix operators such as `[]` and `()` bind more tightly than the pointer `*`, unless parentheses change the grouping.

  10. 10. What is the main purpose of parentheses in a complicated C declaration?

    • A. To change the data type of a variable
    • B. To control the binding and grouping of declarators
    • C. To allocate memory
    • D. To initialize variables
    Show answer

    B. To control the binding and grouping of declarators

    Parentheses can change how pointers, arrays, and functions are grouped, making declarations such as pointer-to-array or pointer-to-function possible.

  11. 11. What does the declaration `char (*p)[20];` declare?

    • A. An array of 20 character pointers
    • B. A pointer to an array of 20 characters
    • C. A pointer to 20 character variables
    • D. A function returning a character pointer
    Show answer

    B. A pointer to an array of 20 characters

    The parentheses group `*p`, making `p` a pointer. The `[20]` then specifies that it points to an array of 20 characters.

  12. 12. What does `int (*fp)(int, int);` declare?

    • A. A function taking two integers and returning a pointer
    • B. A pointer to a function taking two integers and returning int
    • C. An array of two integer pointers
    • D. A pointer to two integer variables
    Show answer

    B. A pointer to a function taking two integers and returning int

    The parentheses around `*fp` make `fp` a function pointer. The pointed-to function accepts two int parameters and returns int.

  13. 13. What does the declaration `int *(*p)[10];` declare?

    • A. A pointer to an array of 10 pointers to int
    • B. An array of 10 pointers to a pointer
    • C. A pointer to a function returning an array
    • D. An array of 10 integers
    Show answer

    A. A pointer to an array of 10 pointers to int

    The declaration makes `p` a pointer to an array of 10 elements, where each element is a pointer to int.

  14. 14. Which technique is commonly used to interpret a complicated C declaration?

    • A. Read only the data type from left to right
    • B. Start at the identifier and follow the declarator outward, respecting parentheses
    • C. Ignore all parentheses
    • D. Read only the operators before the identifier
    Show answer

    B. Start at the identifier and follow the declarator outward, respecting parentheses

    A useful approach is to start at the declared identifier and work outward, following arrays, functions, and pointers while respecting parentheses.

  15. 15. What does the declaration `void (*signal_handler)(int);` represent?

    • A. A function returning a pointer to void
    • B. A pointer to a function taking an int and returning void
    • C. A pointer to an integer
    • D. An array of void functions
    Show answer

    B. A pointer to a function taking an int and returning void

    The parentheses around `*signal_handler` indicate that it is a function pointer. The function takes an int argument and returns void.