edited by
5,715 views

5 Answers

Best answer
14 votes
14 votes

Answer: (d)

Explanation: Given program fragment is without braces, it is equivalent with braces will be like this:
if (a > b)
{
    if (b > c) { s1; }
    else { s2; }
}

Note: A expression's scope remains until its sub expressions does not complete.

Reference: Executed program on URL: https://ideone.com/GmMM5E

selected by
3 votes
3 votes
Point here to be noted is that when I write if (a >b) now after this I haven't written any braces so anything written within it would be considered as a single statement hence it is equivalent to if(a>b){ if (b < c) {s1 ;} else {s2 ;}

therefore clearly if s2 has to execute then we must have the condition a>b to be true simultaneously with b<=c , so option D is correct .
1 votes
1 votes
 
 

C compiler parses every else statement greedily ie every else statement will match the nearest if statement. Hence the correct representation is 

if(a>b)
{
      if(b>c)
          s1;
      else
          s2;

}

 

Answer is D

Answer:

Related questions

9 votes
9 votes
5 answers
2
go_editor asked Jun 21, 2016
6,129 views
The for loopfor (i=0; i<10; ++i) printf("%d", i&1);prints0101010101011111111100000000001111111111
10 votes
10 votes
4 answers
3
go_editor asked Jun 21, 2016
9,383 views
The output of the following program ismain() { static int x[] = {1,2,3,4,5,6,7,8} int i; for (i=2; i<6; ++i) x[x[i]]=x[i]; for (i=0; i<8; ++i) printf("%d", x[i]); }1 2 3 ...
8 votes
8 votes
2 answers
4
go_editor asked Jun 21, 2016
7,636 views
Consider the following program fragmenti=6720; j=4; while (i%j)==0 { i=i/j; j=j+1; }On termination j will have the value4896720