Which statement about a function returning a pointer is correct in C?

Options

  • A. A function can return a pointer to a valid global object
  • B. A function can safely return a pointer to a local automatic variable
  • C. A function returning a pointer must always return NULL
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. A function can return a pointer to a valid global object

Detailed Explanation

Correct Answer: Option A

Explanation:
A function may return a pointer to a global object or to dynamically allocated memory, provided the pointer remains valid. Returning the address of a local automatic variable is unsafe because that variable lifetime ends when the function returns, leaving a dangling pointer.