OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

QUESTION 42 Which one of the given options is correct with respect to the return statement...

Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.

QUESTION 42

Which one of the given options is correct with respect to the return statement of the function declaration given below?

int h (int (* s) (int, int), int x, int y);
Choose one option.
Show answer & explanation
Answer: D. return (* p) (x, y);

The function h returns an int and receives a function pointer s (which takes two int parameters and returns an int) plus two int parameters x and y. The correct return statement must dereference and invoke the function pointer with the two arguments. Option D correctly uses (* p) (x, y) to call the function pointed to by p with arguments x and y, which returns an int. Options A and B are syntactically invalid (dereferencing a function pointer or mixing syntax incorrectly), and Option C returns a hardcoded value rather than invoking the function pointer.

Step-by-step Derivation:

  1. Analyze the function signature: int h (int (* s) (int, int), int x, int y);

    • Return type: int
    • Parameter 1: int (* s) (int, int) — a pointer to a function taking two ints and returning int
    • Parameter 2: int x — integer
    • Parameter 3: int y — integer
  2. To return an int, we must either:

    • Return a constant integer, OR
    • Call the function pointer s (or p in the options) with the appropriate arguments
  3. Evaluate each option:

    • A) return *p; — Dereferencing a function pointer gives the function itself, not a valid return value of type int.
    • B) return (* p) (x, y) (*x, *y); — Syntax error; mixing function call with invalid dereference of integers.
    • C) return 0; — Valid syntax but ignores the function pointer parameter; not the intended use.
    • D) return (* p) (x, y); — Correctly dereferences p, invokes it with arguments x and y, and returns the resulting int.
  4. Correct answer: D