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;
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.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development