Question 66Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)

In C programming, which of the following is correct about why all pointers should be

In C programming, which of the following is correct about why all pointers should be set to NULL if they are not pointing to anything?
  1. AWhen a pointer is initialized to NULL, it does not help in avoiding dangling pointers (pointers that reference invalid or deallocated memory).
  2. BSetting pointers to NULL is merely a norm and has no effect on program execution.
  3. CIf a pointer is not pointing to anything, the program won’t execute at all, giving a syntax error message.
  4. DWhen a pointer is initialized to NULL, it signifies that the pointer does not currently reference any valid memory location.
Show answerHide answer

Correct answer: (D) When a pointer is initialized to NULL, it signifies that the pointer does not currently reference any valid memory location.

Explanation

A NULL pointer explicitly marks that the pointer refers to no valid memory, so the code can test if (p == NULL) before use, avoiding accidental use of garbage or dangling addresses.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 2 (1:00 PM)

This is question 66 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 2 (1:00 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.