Vous êtes sur la page 1sur 18

Objective type questions on c with answers for interview C programming language objective questions and answers

(1) #define max value 10 int main(){ int a=60; if(a/max value==6) printf("equal"); else printf("not equal"); return 0; } What will be output if you compile and execute the above code? (a)equal (b)not equal (c)Run time error (d)Compiler error (2) #define num int long int main(){ num a=0; printf("%d,%d,%d",a++,sizeof a++,sizeof(a++)); return 0; } What will be output if you compile and execute the above code? (a)3 2 4 (b)0 0 4 (c)0 4 4 (d)Compiler error (3) #define short int long

int main(){ printf("%d",sizeof(short)); return 0; } What will be output if you compile and execute the above code? (a)2 (b)4 (c)8 (d)Compiler error (4) #define float char int main(){ float f=255; printf("%d",sizeof(f++)); return 0; } What will be output if you compile and execute the above code? (a)1 (b)2 (c)8 (d)Compiler error (5) int main(){ char f=255.0; printf("%d",sizeof(f++)); return 0; } What will be output if you compile and execute the above code? (a)1 (b)8 (c)10

(d)Compiler error (6) int main(){ char f=255; f++; printf("%d",sizeof(f)); return 0; } What will be output if you compile and execute the above code? (a)1 (b)2 (c)4 (d)Compiler error (7) #define value 10\2 int main(){ printf("%d",value); return 0; } What will be output if you compile and execute the above code? (a)5 (b)20 (c)102 (d)Compiler error (8) #define xxx 11\ 3 int main(){ printf("%ld",xxx); return 0; } What will be output if you compile and execute the above code?

(a)11 (b)3 (c)113 (d)Compiler error (9) #define option1 a++; printf("%d",a); #define option2 print("%d",a); int main(){ int a=10; if(a++) option1 else option2; } What will be output if you compile and execute the above code? (a)10 (b)11 (c)12 (d)Compiler error (10) //test.c int main(){ printf("%s",__FILE__); } What will be output if you compile and execute the above code? (a)null (b)test.c (c)url of current working directory (d)Compiler error (11) #include"stdio.h" int main(){ #ifdef __stdio_h prinrf("defined");

#else printf("not defined"); #endif return 0; } What will be output if you compile and execute the above code? (a) defined (b) not defined (c)Run time error (d)Compiler error (12) #include"stdio.h" int main(){ const int a=1; #if 5+~5+1 printf("%d",a+1); #elif 7 printf("%d",a+2); #else printf("%d",a+3); #endif return 0; } What will be output if you compile and execute the above code? (a)2 (b)3 (c)4 (d)Compiler error (13) #define conio.h #include "stdio.h" #define max 0\5 int main(){ #ifndef __conio_h

#define conio.h printf("%s",__TIME__); #else #undef __conio_h printf("%s",__DATE__); #endif return 0; } What will be output if above code? (a)Output will be date (b)Output will be time (c)Output will be both compilation (d)Compiler error you compile and execute the of compilation of compilation time of compilation and date of

(14) #define max 5 #define a max*max #define value a\a int main(){ const int aa=5; printf("%d",value+aa); return 0; } What will be output if you compile and execute the above code? (a)5 (b)6 (c)10 (d)Compiler error (15) #define function(a,b) a##b int main(){ printf("%d",function(5,2)); return 0; }

What will be output if you compile and execute the above code? (a)10 (b)2 (c)52 (d)Compiler error (16) #define find(a,b,c) #a#b#c int main(){ int a=10; int b=20; int c=30; printf("%s",find(a,b,c)+1); return 0; } What will be output if you compile and execute the above code? (a)102030 (b)02030 (c)bc (d)Compiler error (17) #define swap(x,y) x^=y^=x^=y int main(){ int a=10,b=20; swap(a,b); printf("%d %d" ,a,b); return 0; } What will be output if you compile and execute the above code? (a)10 20 (b)20 10 (c)0 10 (d)Compiler error (18)

#define int long #define cal(x,y,z) x*y*z int main(){ int a=2; int b=cal(a++,a++,a++); printf("%d,%d" ,a,b); return 0; } What will be output if you compile and execute the above code? (a)5,0 (b)5,125 (c)5,60 (d)Compiler error (19) #define final(a,b,c) ++a+ ++b+ ++c int main(){ printf("%d" ,final(1,2,3)); return 0; } What will be output if you compile and execute the above code? (a)6 (b)9 (c)10 (d)Compiler error (20) void one(); void two(); #pragma startup one 2 #pragma startup two 1 int main(){ printf("main "); return 0; } void one() {

printf("one "); } void two() { printf("two "); } What will be output if you compile and execute the above code? (a)main one two (b)one main two (c)main (d)two main one Answer of c programming objective types questions and answers 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. (d) (c) (b) (a) (a) (a) (c) (c) (d) (b) (b) (b) (b) (c) (c) (c) (b) (a) (d) (d)

Q1. What will be the output of the following arithmetic expression ? 5+3*2%10-8*6

a) -37 b) -42 c) -32 d) -28 Q2. What will be the output of the following statement ? int a=10; printf("%d &i",a,10); a) error b) 10 c) 10 10 d) none of these Q3. What will be the output of the following statement ? printf("%X%x%ci%x",11,10,'s',12); a) error b) basc c) Bas94c d) none of these Q4. What will be the output of the following statements ? int a = 4, b = 7,c; c = a = = b; printf("%i",c); a) 0 b) error c) 1 d) garbage value Q 5. What will be the output of the following statements ? int a = 5, b = 2, c = 10, i = a>b void main() { printf("hello"); main(); } a) 1 b) 2 c) infinite number of times d) none of these

Q7. What will be the output of the following statements ? int x[4] = {1,2,3}; printf("%d %d %D",x[3],x[2],x[1]); a) 03%D b) 000 c) 032 d) 321 Q8. What will be the output of the following statement ? printf( 3 + "goodbye"); a) goodbye b) odbye c) bye d) dbye

Q9. What will be the output of the following statements ? long int a = scanf("%ld%ld",&a,&a); printf("%ld",a); a) error b) garbage value c) 0 d) 2 Q10. What will be the output of the following program ? #include void main() { int a = 2; switch(a) { case 1: printf("goodbye"); break; case 2: continue; case 3: printf("bye"); }

} a) error b) goodbye c) bye d) byegoodbye

Q11. What will be the output of the following statements ? int i = 1,j; j=i--- -2; printf("%d",j); a) error b) 2 c) 3 d) -3 Q12. What will be the output of following program ? #include main() { int x,y = 10; x = y * NULL; printf("%d",x); } a) error b) 0 c) 10 d) garbage value Q13. What will be the output of following statements ? char x[ ] = "hello hi"; printf("%d%d",sizeof(*x),sizeof(x)); a) 88 b) 18 c) 29 d) 19

Q14. What will be the output of the following statements ? int a=5,b=6,c=9,d; d=(ac?1:2):(c>b?6:8)); printf("%d",d); a) 1 b) 2 c) 6 d) 8 Q15. What will be the output of the following statements ? int i = 3; printf("%d%d",i,i++); a) 34 b) 43 c) 44 d) 33 Q16. What will be the output of the following program ? #include void main() { int a = 36, b = 9; printf("%d",a>>a/b-2); } a) 9 b) 7 c) 5 d) none of these

Q17) int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain? a) 11 b) 7 c) 5 d) 9

Q18) void main() { int a=10,b=20; char x=1,y=0; if(a,b,x,y) { printf("EXAM"); } } What is the output? 1) XAM is printed 2) exam is printed 3) Compiler Error 4) Nothing is printed Q19) What is the output of the following code? #include void main() { int s=0; while(s++<10)> # define a 10 main() { printf("%d..",a); foo(); printf("%d",a); } void foo() { #undef a #define a 50 } 1) 10..10 2) 10..50

3) Error 4) 0 Q21) main() { struct { int i; }xyz; (*xyz)->i=10; printf("%d",xyz.i); } What is the output of this program? 1) program will not compile 2) 10 3) god only knows 4) address of I Q22) What would be the output of the following program? #include main() { char str[]="S\065AB"; printf("\n%d", sizeof(str)); }

1) 7 2) 6 3) 5 4) error Q23) What will be the value of `a` after the following code is executed #define square(x) x*x a = square(2+3) 1) 25 2) 13

3) 11 4) 10 Q24) #include void func() { int x = 0; static int y = 0; x++; y++; printf( "%d -- %d\n", x, y ); } int main() { func(); func(); return 0; } What will the code above print when it is executed? 1) 1 -- 1 1 -- 1 2) 1 -- 1 2 -- 1 3) 1 -- 1 2 -- 2 4) 1 -- 1 1 -- 2 Q25) long factorial (long x) { ???? return x * factorial(x - 1); } With what do you replace the ???? to make the function shown above return the correct answer?

1) if (x == 0) return 0; 2) return 1; 3) if (x >= 2) return 2; 4) if (x <= 1) return 1; Q 26) int y[4] = {6, 7, 8, 9}; int *ptr = y + 2; printf("%d\n", ptr[ 1 ] ); What is printed when the sample code above is executed? 1) 6 2) 7 3) 8 4) 9 . Q27) int i = 4; switch (i) { default: ; case 3: i += 5; if ( i == 8) { i++; if (i == 9) break; i *= 2; } i -= 4; break; case 8: i += 5;

break; } printf("i = %d\n", i); What will the output of the sample code above be? 1) i = 5 2) i = 8 3) i = 9 4) i = 10

Answers: 1.(a)-37 2.(d)none of them 3.(b)basc 4.(a)0 5.(c)infinite number of time 7.(c)032 8.(d)dbye 9.(b)garbage value 10.(a) error 11.(c) 3 12.(b)0 13.(d) 1 9 14.Error 15.(b)4 3 16.(a) 9 17.(a) 11 18.(d) nothing will be print 19.(3) Error 21.(2)10 22.(2) 6 23.(3) 11 24.(4)1..1,1..2 25.(4)if(x<=1)return 1; 26. (4) 9 27.(1) i=5

Vous aimerez peut-être aussi