GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 7.5

Nil pointer dereference

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 1993 paper

GATE 1993, Q7.5 2 marks · MSQ
Report issue

Semantic Analysis & Type Checking

Question 7.5, GATE 1993: Pascal allocates ptr, assigns ptr:=nil, then attempts ptr^.d:=5.2 and prints the reproduced text write ln(ptr). Which error claims are justified?
Tap to enlarge
Select all that apply
Answer & solution

Answer: B, D (runtime nil dereference); as printed, A (compile-time error) also applies (no official key was published)

After new(ptr), assigning nil discards the usable pointer. Dereferencing ptr^ then attempts to access a nonexistent record, so a checked execution reports nil-pointer dereference rather than printing 5.2. This supports the intended runtime-error and nil-error choices B,D. Those issues can cause compile-time rejection before runtime. No claim that the literal program necessarily reaches the dereference is made.

Original paper, page 7