CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following ANSI C program:
#include< stdio.h>
int main( )
{
int i, j, count;
count = 0;
i = 0;
for (j = -3; j < = 3; j++)
{
if ((j > = 0)&& (i++))
count = count +j;
}
count = count +i;
printf("%d", count);
return 0;
}
Which one of the following option is correct?


A
The program will compile successfully and output 13 when executed
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
The program will compile successfully and output 10 when executed
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
The program will compile successfully and output 8 when executed.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
The program will not compile successfully.
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B The program will compile successfully and output 10 when executed
j = -3, j = -2, j= -1
Short circuiting in if((j >=0)&&(i++))
j = 0; i = 0 used but i is 1
j = 1; i = 1 used but i is 2
count = 0 + 1 = 1
j= 2; i = 2 used but i is 3
count = 1 +2
j = 3; i = 3 used but i is 4
count = 3 + 3 = 6
count = 6 + 4 = 10
corresponding to count = count + i
Option (d) is correct

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Putting It Together - BODMAS
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon