C Sample Questions – 4
1. What will be the output of the following code:-
int c=20; switch(c)
{
case 19-26:printf("here"); break;
default:printf("there");
break;
}
a)here
b)there
c)No output
d)Error
Ans b
output of the following code:
main()
{
int c=2; if(c=2||3)
printf("%d",c);
else
printf("here");
}
a)1
b)0
c)A
d)here
Ans a
3. find the output of the code given below: int fiAdd(int x,int y);
main()
{
int a=3;
int b=5; printf("%d",fiAdd(a,b));
}
fiAdd(x,y)
{
return(x+y);
}
a)3
b)5
c)8
d)None of the above
Ans c
4.find the output of the code given below: main()
{
int k=3; if(k=4) printf("hello"); else printf("hi");
}
a)hello
b)hi
c)4
d)5
Ans a
5.find the output of the code given below: main()
{
int a; int k; a=1;
for(k=0;k<5;k++)
{
printf("%d %d
|
d) None of the above
|
||||||
%d\n",++a,a++,++a);
|
|||||||
}
|
}
|
Ans a
|
|||||
7) What is the output of the following code
|
|||||||
a)
|
4 2 2
|
snippet?
|
|||||
7 5 5
|
|||||||
10 8 8
|
printf("%d",printf("programming"));
|
||||||
13 11 11
|
|||||||
16 16 16
|
a)
|
programming
|
|||||
b)
|
4 2 2
|
b)
|
programming programming
|
||||
7 5 5
|
c)
|
programming11
|
|||||
10 8 8
|
d) None of the above
|
||||||
13 11 11
|
|||||||
16 14 14
|
Ans c
|
||||||
c)
|
4 2 2
|
||||||
7 5 5
|
8. What is the o/p of the following program?
|
||||||
10 8 8
|
|||||||
13 11 11
|
int i=5;
|
||||||
16 14 16
|
if (i=10)
|
||||||
d)
|
None of the above
|
printf("%d",i);
|
|||||
Ans b
|
a)
|
1
|
|||||
b)
|
5
|
||||||
6.main()
|
c)
|
10
|
|||||
{
|
d) None of the above
|
||||||
int array[3][5] =
|
|||||||
{{1,2,3,4},{10,11,12,13,14},{5,6,7,8}};
|
Ans c
|
||||||
int i;
|
|||||||
int j;
|
9.
|
What is the output of the following
|
|||||
for(i=0;i<3;i++)
|
program?
|
||||||
{
|
for(j=0;j<5;j++)
|
int i;
|
|||||
printf("%d ",array[i][j]);
|
i=1;
|
||||||
}
|
printf("\n");
|
printf("%d %d",i++,i);
|
|||||
}
|
a)
|
0 0
|
|||||
b)
|
1 1
|
||||||
a)
|
1 2 3 4 0
|
c)
|
2 2
|
||||
10 11 12
|
13 14
|
d)
|
1 2
|
||||
5
|
6
|
7
|
8
|
0
|
|||
b)
|
1 2 3 4 0
|
Ans b
|
|||||
10 11 12
|
13 14
|
||||||
c)
|
1 2 3 4 0
|
10) what is the o/p of the following program?
|
|||||
10 11 12
|
13 14
|
||||||
5 6
|
7
|
8
|
int i;
|
for(i=0;i<1;i++) ; i++; printf("%d",i);
a)0
b)1
c)2
d)None of the above
Ans c
11) What is the o/p of the following program?
int i; for(i=0;i<1;i++) i++;
a)0
b)1
c)2
d)None of the above
Ans b
12) What is the o/p of the following program? int i=5;
switch(i)
{
case (i>2): printf("%d",i); break; case(i<2): printf("%d",i++); break;
}
a)1
b)2
c)3
d)Error
Ans d
13)
#include<stdio.h>
main()
{
printf("hi""hello");
}
a)hi
b)hello
c)hihello
d)No output
Ans c
14)
#include<stdio.h>
main()
{
int I =0; printf("%d",++I);
}
what is the answer?
a)0
b)1
c)2
d)3
Ans b
15. Consider, main()
{
float i;
for(i=1; i<10; i++);
{
if (i % 2 == 0) printf("%d ", i);
}
}
What does the program print?
a)0
b)1
c)2 4 6 8 10
d)Error Ans d
16. Consider the following program, #include <stdio.h>
static int a; main()
{
static int i = a;
printf("%d %d", i,a); return 0;
}
What does the program print?
a)0 0
b)1 1
c)0 1
d)No output
Ans a
17. What would be the output of the following program?
main()
{
int i=2;
printf("\n%d %d",++i,++i);
}
a)1 2
b)3 4
c)4 3
d)4 4
Ans c
18. What would be the output of the following program?
main()
{
char a[]="Visual C++";
printf("\n%d",sizeof(a));
}
a)1
b)2
c)10
d)11
Ans d
19. What would be the output of the following program #include<string.h>
main()
{
char str1[] = "Infosys"; char str2[] = "Infosys"; if(str1==str2)
printf("\n Equal"); else
printf("\n UnEqual");
}
a)Equal
b)Unequal
c)No output
d)Error
Ans b
20. What would be the output of the following program?
#include<stdio.h>
main()
{
int a[5]={2,3};
printf("\n %d %d %d",a[2],a[3],a[4]);
}
a)0 0 0
b)0 0 1
c)0 1 0
d)None of the above
Ans a
21.
|
What will be the output of following
|
int iNum =1;
|
|
program?
|
switch(iNum)
|
||
{
|
|||
#include<stdio.h>
|
default: printf("Invalid");
|
||
void main()
|
break;
|
||
{
|
case 1 : printf("One");
|
||
int i,j;
|
break;
|
||
for(i=0;i<=2;i++)
|
case 1 : printf("One more");
|
||
for(j=0;j<=2;j++)
|
break;
|
||
{
|
case 2 : printf("two");
|
||
if(i==j)
|
break;
|
||
continue;
|
|||
printf("%d %d \n",i,j);
|
}
|
||
}
|
}
|
||
}
|
a)
|
One
|
|
b)
|
One more
|
||
a)
|
0 1
|
c)
|
Two
|
0 2
|
d)
|
Compile error
|
|
1 0
|
|||
1 2
|
Ans d
|
||
2 0
|
|||
2 1
|
23. What is the output of the following code
|
||
b)
|
0 1
|
int icount = 1;
|
|
0 2
|
while (icount < 10);
|
||
1 0
|
icount++;
|
||
1 0
|
printf("%d", icount);
|
||
2 0
|
|||
2 1
|
a)
|
1 … 32767
|
|
b)
|
1 … 10
|
||
c)
|
0 1
|
c)
|
Infinite loop
|
0 2
|
d) None of the above
|
||
1 0
|
|||
1 2
|
Ans c
|
||
2 1
|
|||
2 1
|
24. What is the output of the following code
|
||
snippet :
|
|||
d) None of the above
|
int iNum=1;
|
||
switch (iNum)
|
|||
Ans a
|
{
|
||
case 1: printf ("One ");
|
|||
22. Find the output of the following program
|
case 2: printf("Two"); break;
|
||
default : printf ("Invalid");
|
|||
void main()
|
}
|
||
{
|
a)One Two
b)One
c)Two
d)Invalid
Ans a
25. What is the output of the following code?
#include<stdio.h> void main()
{
int i; int k; i = 2; k = 5; if(i=5)
{
printf("%d",k++);
}
printf("%d",++i);
}
a)2 5
b)0 1
c)5 6
d)None of the above
Ans c
26. What will be the output of the following piece of code?
#include<stdio.h> void main()
{
int x,y,z; x=5; y=4; z=0; if(x==0)
if(y==0)
printf("Do
Something"); else
{
z=x+y;
printf("The control is here");
}
}
a)Do Something
b)The control is here
c)No output
d)Compile error
Ans c
27.
int x, y = 2, z, a;
x = (y*= 2) + (z = a = y); printf("%d",x);
a)2
b)4
c)6
d)8
ans d
28. The following statement printf("%f", (float) 9/5);
a)1
b)1.800000
c)No output
d)0.000000
Ans b
29. The following statement printf("%f",9/5);
a)1
b)1.800000
c)No output
d)0.000000
Ans c
30.
|
The following program fragment
|
|||
int i;
|
Ans a
|
|||
for(i = 3; i< 15; i+= 3);
|
||||
printf("%d",i);
|
34.
|
The following program fragment
|
||
int k =
|
||||
a)
|
3 … 15
|
printf("%d", 0 < !k);
|
||
b)
|
3 6 9 12 15
|
|||
c)
|
15
|
a)
|
||
d)
|
Infinite loop
|
b)
|
0
|
|
c)
|
1
|
|||
Ans c
|
d)
|
None of the above
|
||
31.
|
Ans b
|
|||
int i;
|
||||
for(i = 1;i < 5; ++i)
|
35.
|
The following loop
|
||
if(i == 3)
|
for(putchar('c');putchar('a');putchar('r'))
|
|||
continue;
|
putchar('t');
|
|||
else printf("%d",i);
|
a)
|
cart
|
||
a)
|
1 2 3 4
|
b)
|
catratratrat.....
|
|
b)
|
1 2
|
c)
|
c
|
|
c)
|
1 2 3
|
d)
|
None of the above
|
|
d)
|
1 2 4
|
Ans b
|
||
Ans d
|
||||
36.
|
The following loop
|
|||
32.
|
The following program
|
int i,j;
|
||
int a;
|
for(i =1, j = 10; i <6;
|
|||
if( a = 0) printf("a is zero"); else printf("a is
|
printf("%d %d\n",i ,j);
|
|||
non zero");
|
a)
|
1 10
|
||
a)
|
a is non zero
|
2 9
|
||
b)
|
a is zero
|
3 8
|
||
c)
|
No output
|
4 7
|
||
d)
|
Compile error
|
5 6
|
||
b)
|
1 10
|
|||
Ans a
|
2 9
|
|||
3 3
|
||||
33.
|
The following program fragment
|
4 7
|
||
if(a = 7) printf("a is seven"); else printf("a is
|
5 6
|
|||
not seven");
|
c)
|
1 10
|
||
a)
|
a is seven
|
10 9
|
||
b)
|
a is not seven
|
3 3
|
||
c)
|
No output
|
4 7
|
||
d)
|
Compile error
|
5 6
|
d) None of the above
Ans a
37. The following program fragment int a a=4, b= 6;
printf("%d", a != b);
a)4
b)6
c)1
d)0
Ans c
Question 38
The following program fragment int a = 4, b = 6;
printf("%d", a=b );
a)4
b)6
c)1
d)0
Ans b
39. The following program main()
{
int i = 5; if( i == 5) return 0;
else printf("i is not five"); printf("over");
}
a)i is not five
b)execution termination, without printing anything
c)0
d)1
Ans b
40. The following program fragment int i = 5;
do { putchar(i+100);printf("%d",i--);
}
while(i);
a)i5h4g3f2e1
b)i54321
c)ihgfe
d)None of the above
Ans a
41. The following program fragment int i = 107, x= 5;
printf((x > 7) ? "%d" : "%c", i);
a)107
b)5
c)k
d)None of the above
Ans c
42. The following statements int i;
for(i = 3; i< 15; i+=3){ printf("%d ", i);++i;
}
a)3 7 11
b)3 6 9 12 15
c)3
d)None of the above
Ans a
43. The following statement if( 2 < 1 );
else
x = (2 < 0)? printf("one") : printf("four"); printf("%d", x);
a)one
b)four
c)four4
d)None of the above
printf("%d",++x);
|
|||
Ans c
|
}
|
||
44. The following program
|
a)
|
1 1 1
|
|
main()
|
b)
|
2 2 2
|
|
{
|
c)
|
3 3 3
|
|
printf("saradhi");
|
d)
|
1 2 3
|
|
main();
|
|||
}
|
Ans d
|
||
a)
|
saradhi
|
47. printf("ab", "cd", "ef");
|
|
b)
|
saradhi……..
|
||
c)
|
No output
|
a)
|
ab
|
d)
|
Compile error
|
b)
|
cd
|
c)
|
ef
|
||
Ans b
|
d)
|
abcdef
|
|
45. The following program
|
Ans a
|
||
change(int);
|
48
|
||
main()
|
The expression 4+6/3*2 - 2 + 7%3 evaluates
|
||
{
|
to
|
||
int a = 4;
|
|||
change(a);
|
a)
|
5
|
|
printf("%d",a);
|
b)
|
6
|
|
}
|
c)
|
7
|
|
change(int a)
|
d)
|
None of these
|
|
{
|
|||
printf("%d",++a);
|
Ans c
|
||
}
|
49. main ()
|
||
a)
|
4
|
{
|
int a =5, b = 2;
|
b)
|
5
|
printf("%d", a+++b); }
|
|
c)
|
5 4
|
||
d)
|
No output
|
a)
|
5
|
b)
|
2
|
||
Ans c
|
c)
|
7
|
|
46. The following program
|
d)
|
No output
|
|
inc();
|
Ans c
|
||
main()
|
|||
{inc();inc();inc();
|
|||
}
|
|||
inc()
|
|||
{
|
|||
static int x;
|
50. The following program main(){
float a = 0.5, b = 0.7; if(b < 0.7)
if(a < 0.5) printf("TELO"); else printf("LTTE");
else printf("JKLF");
}
a)TELLO
b)LTTE
c)JKLF
d)No ouput
Ans b
No comments:
Post a Comment