Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following 'C' program fragment :

if(tPTR ! = NULL)
    * tPTR = NULL;
else
    * tPTR = NULL;

Select the following statements that are having same effect :

(i) if (tPTR) * tPTR = NULL;
else * tPTR = NULL
(ii) *tPTR = NULL;
(iii) if (!tPTR) * tPTR = NULL;
else * tPTR = NULL;
(iv) if (tPTR = = NULL) * tPTR = NULL;
else * tPTR = NULL;

  • A.(i) and (ii)
  • B.(i), (ii), (iii) and (iv)
  • C.(ii), (iii) and (iv)
  • D.(ii) only

Answer: B

All four have the same effect, so the answer is (i), (ii), (iii) and (iv).

In the given fragment both branches of the if do the same thing, *tPTR = NULL;, so whatever the condition, the effect is just that assignment, which is statement (ii).

Statements (i), (iii) and (iv) also have identical branches. They test different conditions (tPTR non-null, tPTR null, tPTR equal to NULL), but since the same assignment runs either way, the condition changes nothing. The paper sets the operators != and == with a space inside them and leaves the semicolon off the end of (i); read as the intended C, every option naming fewer than four statements leaves out an equivalent one.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.