MCQ - Structure And Loops in C Programming

21. What is the output of this program?

#include<stdio.h>
int main()
{
int a = 5;
if (a == 6); a = 0;
if (a == 5)
a++;
else a += 2;
printf("%d", a);
return 0;
}

A. 6
B. 8
C. 5
D. 2

View Answer


22. What is the output of this program?

#include<stdio.h>
int main()
{
int a = 1, b = 0;
int c = (a++, b++) ? b : a;
printf("%d", c);
return 0;
}

A. 2
B. 1
C. 0
D. 3

View Answer


23. What is the output of this program?
int main()
{
int a = 1, b = 0;
int c = a%2 ? a++ : a-- ? a=0 : ++b ? b = 2 : b++ ;
printf("%d", c);
return 0;
}

A. 1
B. 2
C. 3
D. 0

View Answer


24. What will be the output of the program in 16 bit platform ?

#include<stdio.h>
int main()
{
int a=2, b=1, c=2;
switch(a)
{
case b:
printf("You are in b ");
break;
case c:
printf("You are in c ");
break;
default:printf("You are in default");
}
return 0;
}

A. You are in b
B. You are in c
C. You are in default
D. Compilation Error

View Answer


25. What will be output when you will execute following c code?

#include<stdio.h>
int main()
{
int a=2;
switch(a,a+1)
{
case 2:
printf("You are in b ");
break;
case 3:
printf("You are in c ");
break;
default:
printf("You are in default");
}
return 0;
}

A. You are in b
B. You are in c
C. You are in default
D. Compilation Error

View Answer


26. What is the output of this program?

#include<stdio.h>
void main() {
float a = 0.7;
if ( a < 0.7 )
printf( "Yes" );
else
printf( "No" );
}

A. Yes
B. No
C. Compilation Error
D. None of these

View Answer


27. What is the output of this program?

#include<stdio.h>
void main()
{ char a=0;
for(a=0;a<=127;a++)
{
printf("%d ",a);
}
}

A. 0 1 2 ... 127
B. 0 1 2 ... infinite times
C. Compilation Error
D. None of the above

View Answer


28. How many times the loop will execute ?

for(int i = 0 ; i < 10 ; i++)
{
i = i*2;
i--;
}

A. 10
B. 5
C. 0
D. Infinite

View Answer


29. What is the output of this program?

#include<stdio.h>
void main()
{
int j = -5;
for(;j;printf("%d ", j++));
}

A. -5 to -1
B. -5 to 0
C. -5 to infinity
D. Compilation Error

View Answer


30. What is the output of this program?

void main()
{
int x=0;
for(;;)
{
if(x==3)
break;
printf("%d ",++x);
}
}

A. 1 2 3
B. 0 1 2 3
C. 1 2
D. Compilation Error

View Answer







Also check :


Discussion


* You must be logged in to add comment.