C programming Quiz 1

Q1. Solve the output
#include<stdio.h>
int main()
{
int c=5;
while(--c)
{
printf("Hello World\n");
}
}


Answer: Hello World

        Hello World
        Hello World
        Hello World
Q2. Select the correct option
#include<stdio.h>
int main()
{
float f1=0.1;if(f1==0.1)
printf("Equal\n");
else
printf("Not Equal\n");
}

a. Equal b. Not Equal c. output depens upon compiler 

d. compile time error

Answer: b
Q3. Select the correct one
#include<stdio.h>
int main()
{
int x,y=10;
x=y*NULL;
printf("%d",x);
}

a. 0 b. error c. garbage value d. 10


Answer: a
Q4. Select the correct one
#include<stdio.h>
int main()
{
int a=0XF2;
printf("%d", a);
return 0;
}
a. 2 b. 42 c.242 d. 132
 
Answer: c
Q5. What will be the output of the following code?
#include<stdio.h>
int main()
{
int a=0,b=1,c=2;
((a+1)==1? &b:&a)=a?b:c;
printf("%d %d %d\n",a,b,c);
return 0;
}
a. 0,1,2 b.1,1,2 c. 2,2,2 d. 0,2,2
Answer:
Q6. Select the correct option
#include<stdio.h>
int main()
{
int a=10;
a=a<<2 br=""> printf("%d",a);
}

<2 br="">
Answer: 10
Q7. What will be the output of the following code?
#include<stdio.h>

void AddPrint()
{
static int s=1;
s++;
printf("%d",s);
}
int main()
{
AddPrint();
AddPrint();
AddPrint();
}
a. 2 3 4 b. 1 2 3 c. 1 1 1 d. 2 2 2
 
Answer: a
Q8. What will be the output of following code?
int main()
{
int x,y=10,z=10;
x=(y==z);
printf("%d",x);
}
a. Garbage Value b. 10 c. 1 d. Compilation Error
 
Answer: c
Q9. Fill in the blanks with correct options:
print "Hello World" using if condition only
#include<stdio.h>
int main()
{
if(________________)
{
}
else
{
printf("World");
}
}


Answer: printf("Hello World");
Q10. Select the correct option
#include<stdio.h>
int main()
{
int i,j,ans=0;
for(i=0;i<2 br="" i=""><2;i++) {
for(int j=i+1;j<=2;j++)
ans+=++ans;
}
printf("%d",ans);
}

<2 br="" i="">


Answer: 14

No comments:

Post a Comment