Exercise

1. What is the output of this program?

void main()
{
if(!printf(""))
printf("hello");
else
printf("world");
}

A. hello
B. world
C. Compilation Error
D. None of the above

View Answer


2. What is the output of this program?

#include <stdio.h>
void main()
{
int a=10;
if(a=5)
printf("YES");
else
printf("NO");
}

A. YES
B. NO
C. Error
D. None of the above

View Answer


3. What is correct about the given program?

#include <stdio.h>
int x;
void main()
{
if (x);
else
printf("Ëlse");
}

A. if block will be executed
B. else block will be executed
C. Depends on value of x since it is undeclared
D. Compilation Error

View Answer


4. 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


5. 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


6. 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


7. 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


8. 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


9. 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


10. 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


11. 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


12. 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


13. 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


14. How many times letsfindcourse will be printed?

#include<stdio.h>
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i += 1;
continue;
}
printf("letsfindcourse");
}
return 0;
}

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

View Answer


15. What is the output of this program?

#include<stdio.h>
void main()
{
int a = 3;
while (a--)
{
int a = 10;
a--;
printf("%d ", a);
}
}

A. 9 9 9
B. 9 8 7
C. 2 1 0
D. Infinite loop

View Answer


16. Which of the given statment is true about the given code ?

int main()
{
int i = 0;
for ( ; i < 5 ; )
{
if (i < 5)
printf("Hello", i++);
else
continue;
printf(“World”);
}
return 0;
}

A. It will print hello 5 times followed by World one time
B. It will print helloWorld 5 times
C. It will print helloWorld infinite times
D. Compilation Error

View Answer


17. How many times value of j is checked in the below code ?

int main()
{
int j = 0;
do {
j++;
printf("\n");
} while (j < 5);
}

A. 3
B. 4
C. 5
D. 1

View Answer



Discussion

* You must be logged in to add comment.