17.4 – Quiz on Console I/O

by subbu on October 8, 2014

Quiz

1. What would be the output of following program?

#include<stdio.h>
int main()
{
 short x=10,y=20;
 printf("%d",printf("%d\t%d\t",x,y));
 return 0;
}
Show Answer
Output
10     20     6

2. What would be the output of following program?

#include<stdio.h>
int main()
{
 short x=10,y=20;
 printf("%d",printf("%d %d ",x,y));
 return 0;
}
Show Answer
Output
10      20      6

3. What would be the output of following program?

#include<stdio.h>
int main()
{
 short x=10,y=20;
 printf("%d\t%d\t%d",x,y);
 return 0;
}
Show Answer
Output in turbo C
10      20      20

Output in gcc
10      20

4. What would be the output of following program?

#include<stdio.h>
int main()
{
 short x=10,y=20;
 printf("%d",x,y);
 return 0;
}
Show Answer
Output
10

5. What would be the output of following program?

#include<stdio.h>
int main()
{
 if(printf("Hello"))
   printf(" World");
 return 0;
}
Show Answer
Output
Hello World

6. What would be the output of following program?

#include<stdio.h>
int main()
{
 int x;
 scanf("%d",x);
 printf("x=%d",x);
 return 0;
}
Show Answer
Output
Unexpected behavior

7. What would be the output of following program?

#include<stdio.h>
int main()
{
 char x[]="hello world";
 char s[50];
 sscanf(x,"%s",s);
 printf("%s",s);
 return 0;
}
Show Answer
Output
hello

8. What would be the output of following program?

#include<stdio.h>
int main()
{
 char x[]="hello world";
 char s[50];
 sprintf(s,"%s",x);
 printf("%s",s);
 return 0;
}
Show Answer
Output
hello world

9. What would be the output of following program?

#include<stdio.h>
int main()
{
 int x=97;
 putchar(x);
 return 0;
}
Show Answer
Output
a

10. What would be the output of following program?

#include<stdio.h>
int main()
{
 char ch='A';
 putchar(ch++);
 putchar('\n');
 putchar(ch+2);
 return 0;
}
Show Answer
Output
A
D

11. What would be the output of following program?

#include<stdio.h>
int main()
{
 char ch,dh;
 ch='A';
 dh=putchar(ch+2);
 putchar('\n');
 putchar(dh-1);
 return 0;
}
Show Answer
Output
C
B

12. What would be the output of following program if user input to the program is “hello”?

#include<stdio.h>
int main()
{
 char x[50];
 char *y;
 y=gets(x);
 printf("%s\n%s",x,y);
 return 0;
}
Show Answer
Output
hello
hello

13. What would be the output of following program if user input to the program is “35”?

#include<stdio.h>
int main()
{
 int x;
 if(scanf("%d",&x))
   printf("x=%d",x);
 return 0;
}
Show Answer
Output
x=35

Previous post:

Next post: