The correct statement for a function that takes pointer to a float, a pointer…

2023

The correct statement for a function that takes pointer to a float, a pointer to a char and returns a pointer to a pointer to an integer is

  1. A.

    int **fun(float*, char **)

  2. B.

    int fun(float, char *)

  3. C.

    int **fun(float*, char **)

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 73 students.

Show answer & explanation

Correct answer: E

C declarators mirror how a value is later dereferenced: a pointer to a type T is written T *, and a pointer to a pointer to T is written T **. In a function declarator, the return type's stars sit immediately before the function name, and each parameter's stars sit before that parameter in the list -- so a function taking a float* and a char* and returning an int** must be declared exactly as int **fun(float *, char *).

Checking each explicit statement against this required declaration:

  1. int **fun(float*, char **) -- the return type (int**) and first parameter (float*) match, but the second parameter is char** (pointer to a pointer to char) where a single char* is required.

  2. int fun(float, char *) -- the second parameter (char *) matches, but the return type is written as plain int and the first parameter as plain float, with none of the required stars.

  3. int **fun(float*, char **) -- identical to the first statement, so it carries the exact same second-parameter mismatch.

Independently rewriting the target type-by-type -- return int **, first parameter float *, second parameter char * -- confirms none of the three statements matches on all three parts, and since two of the three are identical, at most one distinct declaration is even being offered, so more than one of them cannot be correct either. With every explicit statement ruled out, None of the above is the correct choice.

Explore the full course: Up Lt Grade Assistant Teacher 2025