C Sample Questions - 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

C Sample Questions – 4

1. What will be the output of the following int b=5;


code:- printf("%d",fiAdd(a,b));
int c=20; }
switch(c)
{ fiAdd(x,y)
case 19-26:printf("here"); {
break; return(x+y);
default:printf("there"); }
break;
} a) 3
b) 5
a) here c) 8
b) there d) None of the above
c) No output
d) Error Ans c

Ans b 4.find the output of the code given below:


main()
2. {
output of the following code: int k=3;
if(k=4)
main() printf("hello");
{ else
int c=2; printf("hi");
if(c=2||3) }
printf("%d",c);
else a) hello
printf("here"); b) hi
} c) 4
d) 5
a) 1
b) 0 Ans a
c) A
d) here 5.find the output of the code given below:
main()
Ans a {
int a;
3. find the output of the code given below: int k;
int fiAdd(int x,int y); a=1;
main() for(k=0;k<5;k++)
{ {
int a=3;
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?
755
10 8 8 printf("%d",printf("programming"));
13 11 11
16 16 16 a) programming
b) 4 2 2 b) programming programming
755 c) programming11
10 8 8 d) None of the above
13 11 11
16 14 14 Ans c
c) 4 2 2
755 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) 00
b) 11
a) 1 2 3 4 0 c) 22
10 11 12 13 14 d) 12
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
56 7 8 int i;
for(i=0;i<1;i++) ; 13)
i++; #include<stdio.h>
printf("%d",i); main()
{
a) 0
b) 1 printf("hi""hello");
c) 2
d) None of the above }

Ans c a) hi
b) hello
c) hihello
11) What is the o/p of the following program? d) No output

int i; Ans c
for(i=0;i<1;i++)
i++; 14)
i--; #include<stdio.h>
printf("%d",i); main()
{
a) 0 int I =0;
b) 1 printf("%d",++I);
c) 2 }
d) None of the above what is the answer?

Ans b a) 0
b) 1
12) What is the o/p of the following program? c) 2
int i=5; d) 3
switch(i)
{ Ans b

case (i>2): 15. Consider,


printf("%d",i); main()
break; {
case(i<2): float i;
printf("%d",i++); for(i=1; i<10; i++);
break; {
} if (i % 2 == 0)
printf("%d ", i);
a) 1 }
b) 2 }
c) 3
d) Error What does the program print?

Ans d
a) 0 printf("\n%d",sizeof(a));
b) 1 }
c) 2 4 6 8 10
d) Error a) 1
Ans d b) 2
c) 10
16. Consider the following program, d) 11
#include <stdio.h>
static int a; Ans d
main()
{ 19. What would be the output of the
static int i = a; following program
#include<string.h>
printf("%d %d", i,a); main()
return 0; {
} char str1[] = "Infosys";
char str2[] = "Infosys";
What does the program print? if(str1==str2)
printf("\n Equal");
a) 00 else
b) 11 printf("\n UnEqual");
c) 01 }
d) No output
a) Equal
Ans a b) Unequal
c) No output
17. What would be the output of the d) Error
following program?
main() Ans b
{
int i=2; 20. What would be the output of the
printf("\n%d %d",++i,++i); following program?
}
#include<stdio.h>
a) 12 main()
b) 34 {
c) 43 int a[5]={2,3};
d) 44 printf("\n %d %d %d",a[2],a[3],a[4]);
}
Ans c
a) 000
18. What would be the output of the b) 001
following program? c) 010
main() d) None of the above
{
char a[]="Visual C++"; 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
02 d) Compile error
10
12 Ans d
20
21 23. What is the output of the following code

b) 0 1 int icount = 1;
02 while (icount < 10);
10 icount++;
10 printf("%d", icount);
20
21 a) 1 … 32767
b) 1 … 10
c) 0 1 c) Infinite loop
02 d) None of the above
10
12 Ans c
21
21 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 z=x+y;
c) Two printf("The control is here");
d) Invalid }
}
Ans a
a) Do Something
25. What is the output of the following code? b) The control is here
c) No output
#include<stdio.h> d) Compile error
void main()
{ Ans c
int i;
int k; 27.
i = 2; int x, y = 2, z, a;
k = 5; x = (y*= 2) + (z = a = y);
if(i=5) printf("%d",x);
{
printf("%d",k++); a) 2
} b) 4
printf("%d",++i); c) 6
} d) 8

ans d
a) 25
b) 01 28. The following statement
c) 56 printf("%f", (float) 9/5);
d) None of the above
a) 1
Ans c b) 1.800000
c) No output
26. What will be the output of the following d) 0.000000
piece of code?
Ans b
#include<stdio.h>
void main() 29. The following statement
{ printf("%f",9/5);
int x,y,z; a) 1
x=5; b) 1.800000
y=4; c) No output
z=0; d) 0.000000
if(x==0)
if(y==0) Ans c
printf("Do
Something");
else
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 = -7;
a) 3 … 15 printf("%d", 0 < !k);
b) 3 6 9 12 15
c) 15 a) –7
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) 1234 b) catratratrat.....
b) 12 c) c
c) 123 d) None of the above
d) 124
Ans b
Ans d
36. The following loop
32. The following program int i,j;
int a; for(i =1, j = 10; i <6; ++i,--j)
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 29
b) a is zero 38
c) No output 47
d) Compile error 56
b) 1 10
Ans a 29
33
33. The following program fragment 47
if(a = 7) printf("a is seven"); else printf("a is 56
not seven");
c) 1 10
a) a is seven 10 9
b) a is not seven 33
c) No output 47
d) Compile error 56
d) None of the above 40. The following program fragment
int i = 5;
Ans a do { putchar(i+100);printf("%d",i--);
}
37. The following program fragment while(i);
int a a=4, b= 6;
printf("%d", a != b); a) i5h4g3f2e1
b) i54321
a) 4 c) ihgfe
b) 6 d) None of the above
c) 1
d) 0 Ans a

Ans c 41. The following program fragment


int i = 107, x= 5;
Question 38 printf((x > 7) ? "%d" : "%c", i);
The following program fragment
int a = 4, b = 6; a) 107
printf("%d", a=b ); b) 5
c) k
a) 4 d) None of the above
b) 6
c) 1 Ans c
d) 0
42. The following statements
Ans b int i;
for(i = 3; i< 15; i+=3){ printf("%d ", i);++i;
39. The following program }
main()
{ a) 3 7 11
int i = 5; b) 3 6 9 12 15
if( i == 5) c) 3
return 0; d) None of the above
else printf("i is not five");
printf("over"); Ans a
}
43. The following statement
a) i is not five if( 2 < 1 );
b) execution termination, without printing else
anything x = (2 < 0)? printf("one") : printf("four");
c) 0 printf("%d", x);
d) 1
a) one
Ans b b) four
c) four4
d) None of the above
printf("%d",++x);
Ans c }

44. The following program a) 111


main() b) 222
{ c) 333
printf("saradhi"); d) 123
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) 54
d) No output a) 5
b) 2
Ans c c) 7
d) No output
46. The following program
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

You might also like