C Quest
C Quest
[50 x 1]
Predict the output of the following program:
1. main()
{
int x=10,y=5,p,q;
p=x>9;
q=x>3&& y!=3;
printf(“p=%d q=%d”,p,q);
}
a. p= 0 q=1
b. p=1 q=1
c. p=1 q=0
d. p=0 q=0
2. main()
{
int a=30,b=40,x;
x=(a!=10)&&(b=50);
printf(“x=%d”,x);
}
a. x=1
b. x= 0
3. main()
{
int a=100,b=200,c;
c=(a==100 || b>200);
printf(“c=%d”,c);
}
a. c= 0
b. c=1
4. main()
{
int x=11,y=6,z;
z=x==5|| y!=4;
printf(“z=%d”,z);
}
a. z=0
b. z=1
5. main()
{
int x=3,y=4,z=4;
printf(“ans=%d”,z>=y>=x?100:200);
}
a. ans=200
b. ans=300
c. ans=100
d. None of the above
6. main()
{
if(!3.14)
printf(“Welcome”);
else
printf(“Hello”);
}
a. Welcome
b. Hello
c. Welcome Hello
d. Will generate an error
7. main()
{
float a=12.25,b=13.65;
if(a=b)
printf(“a and b are equal”);
else
printf(“a and b are not equal”);
}
8. main()
{
int x=10,y=20;
x=!x;
y=!y;
printf(“x=%d y=%d”,x,y);
}
a. x= 0 y= 0
b. x=1 y=0
c. x=1 y=1
d. x=0 y=1
9.
main()
{
int i= -4, j, num=10;
j=i% -3;
j=(j ? 0:num*num);
printf(“j=%d”,j);
}
a. j=0
b. j=100
e. None of the above
10. main()
{
int x=10,y=20;
x !=x;
y=!x && !y;
printf(“x=%d y=%d”,x,y);
}
a. x=10 y= 0
b. x=1 y=1
c. x=1 y=0
11. main()
{
int x=100;
if(!!x)
printf(“x=%d”,!x);
else
printf(“x=%d”,x);
}
a. x=0
b. x= 1
c. 100
12. main()
{
int a=5;
do
{
printf(“%d ”,a);
a=-1;
}while(a>0);
}
a. 5 4 3 2 1
b. 5
c. 5 4 3 2 1 0
13. main()
{
int x=3,z;
z=x++ +10;
printf(“x=%d z=%d”,x ,z);
}
a. x=4 z=15
b. x=4 z=13
c. x=3 z=15
d. x=3 z=13
14. main()
{
int x=3,y,z;
z=y=x;
z=y+=x=-z;
printf(“x=%d y=%d z=%d”,x,y,z);
}
15. main()
{
int n[25];
n[0]=100;
n[24]=200;
printf(“%d %d”,*n,*(n+24)+*(n+0));
}
a. 100 200
b. 100 300
c. 300 100
d. None of the above
16. main()
{
static int a[]={2,4,6,8,10};
int i;
for(i=0;i<=4;i++)
{
*(a+i)=a[i]+i[a];
printf(“%d”,*(i+a);
}
}
a. 4 8 12 16 20
b. 2 4 8 12 16
c. 2 4 8 12 16
e. None of the above
17. main()
{
printf(“%d”,4%3);
printf(“%d”,4%-3);
printf(“%d”,-4%3);
printf(“%d”,-4%-3);
}
a. 1 1 1 1
b. 1 –1 1 1
c. 1 1 –1 –1
d. –1 1 –1 1
18. main()
{
float a=5,b=2;
int c;
c=a%b;
printf(“%d”,c);
}
a. 2
b. 1
c. Error message
d. None of the above
19. main()
{
int a,b;
a=5.999999;
b=5.000001;
float c;
c=4/2;
printf(“a =%d b=%d”,a,b);
printf(“%f”,c);
}
20. main()
{
printf(“%d”,4/3);
printf(“%d”,4/-3);
printf(“%d”,-4/3);
printf(“%d”,-4/-3);
}
e. 1 1 1 1
f. 1 –1 -1 1
g. 1 1 –1 –1
h. –1 1 –1 1