You are on page 1of 31

C QUESTIONS

1. What will be output when you will execute following c code in turbo c++?
#include<stdio.h> int main() { printf("%d\t",sizeof(6.5)); printf("%d\t",sizeof(90000)); printf("%d",sizeof('A')); return 0; }

(A) 4 2 1 (D) 8 4 1

(B) 8 2 1 (E) 8 4 2

(C) 4 4 1

2. Consider on following declaring of enum. (i) enum cricket {Gambhir,Smith,Sehwag}c; (ii) enum cricket {Gambhir,Smith,Sehwag}; (iii) enum {Gambhir,Smith=-5,Sehwag}c; (iv) enum c {Gambhir,Smith,Sehwag}; A. B. C. D. E. Only (i) is correct declaration Only (i) and (ii) is correct declaration Only (i) and (iii) are correct declaration Only (i),(ii) and are correct declaration All four are correct declaration

3. What will be output when you will execute following c code in turbo c++?

#include<stdio.h> int main() { signed x; unsigned y; x = 10 +- 10u + 10u +- 10; y = x; if(x==y) printf("%d %d",x,y); else if(x!=y) printf("%u %u",x,y); return 0; }

(A) (B) (C) (D)

00 65536 -10 0 65536 65536 0 Compilation (E) error

4. What will be output when you will execute following c code in turbo c++? #include<stdio.h> int main() { double num=5.2; int var=5; printf("%d\t",sizeof(!num)); printf("%d\t",sizeof(var=15/2)); printf("%d",var); return 0; }

(A)
(B) (C) (D) (E)

427
445 225 247 827

What will be output when you will execute following c code?


#include<stdio.h> int main() { const int *p; int a=10; p=&a; printf("%d",*p); return 0; }
(A) 0 (B) 10 (C) Garbage value Any memory (D) address

Error: Cannot (E) modify const object

6. Consider on following declaration: (i) short i=10; (ii) static i=10; (iii) unsigned i=10; (iv) const i=10;

(A) Only (iv) is incorrect (B) Only (ii) and (iv) are incorrect (C) Only (ii),(iii) and (iv) are correct (D) Only (iii) is correct (E) All are correct declaration

7. What will be output when you will execute following c code? #include<stdio.h> int main() { int a= sizeof(signed) +sizeof(unsigned); int b=sizeof(const)+sizeof(volatile); printf("%d",a+++b); return 0; } (A) 10 (B) 9 (C) 8 (D) Error: Cannot find size of modifiers (E) Error: Undefined operator +++

8. What will be output when you will execute following c code? #include<stdio.h> int main() { (A) 10 -10 0 0 signed x,a; unsigned y,b; a=(signed)10u; (B) 10 -10 65516 -10 b=(unsigned)-10; y = (signed)10u + (unsigned)-10; (C) 10 -10 10 -10 x = y; (D) 10 65526 0 0 printf("%d %u\t",a,b); if(x==y) (E) Compilation error printf("%d %d",x,y); else if(x!=y) printf("%u %u",x,y); return 0; }

9. What will be output when you will execute following c code? #include<stdio.h> int main() (A) 11 { (B) Garbage volatile int a=11; (C) -2 printf("%d",a); (D) We cannot predict return 0; (E) Compilation error }

10. What is the range of signed int data type in that compiler in which size of int is two byte? (A) -255 to 255 (B) -32767 to 32767 (C) -32768 to 32768 (D) -32767 to 32768 (E) -32768 to 32767

11. What will be output when you will execute following c code? #include<stdio.h> const enum Alpha { X, Y=5, Z }p=10; int main() { enum Alpha a,b; a= X; b= Z; printf("%d",a+b-p); return 0; }
(A) -4 (B) -5 (C) 10 (E) Error: Cannot modify constant object (D)11

12. What will be output when you will execute following c code?
#include<stdio.h> int main() { char a=250; int expr; expr= a+ !a + ~a + ++a; printf("%d",expr); return 0; }
(A) (B) (C) (D) 249 250 0 -6

(E) Compilation error

13. What will be output when you will execute following c code?
#include<stdio.h> int main(){ int a=-5; unsigned int b=-5u; if(a==b) printf("Avatar"); else printf("Alien"); return 0; }
(A) (B) (C) (D) Avatar Alien Run time error Error: Illegal assignment

(E) Error: Dont compare signed no. with unsigned no.

14. Which of the following is not derived data type in c? (A) Function (B) Pointer (C) Enumeration (D) Array (E) All are derived data type

15. What will be output when you will execute following c code?

#include<stdio.h> enum A { x,y=5, enum B { p=10,q }varp; }varx; int main() { printf("%d %d",x,varp.q); return 0; }

(A) 0 11 (B) 5 10 (C) 4 11 (D) 0 10 (E) Compilation error

16. The keyword used to transfer control from a function back to the calling function is
A. switch B. goto C. go back D. Return

17. What is the notation for following functions? 1. int f(int a, float b) 1. KR 1. Pre ANSI C { /* Some code */ A. Notation B. Notation 2. ANSI 2. KR } Notation Notation 2. int f(a, b) 1. ANSI 1. ANSI int a; float b; Notation Notation C. D. { 2. KR 2. Pre ANSI Notation Notation /* Some code */ }

18. How many times the program will print "abcdef" ? #include<stdio.h> int main() { printf("abcdef"); main(); return 0; } A. Infinite times B. 32767 times C. 65535 times D. Till stack overflows

19. will be the output of the program in 16 bit platform (Turbo C under DOS)? #include<stdio.h> int main() { Garbage A. B. 0 (Zero) int fun(); value int i; i = fun(); C. 1990 D. No output printf("%d\n", i); return 0; } int fun() { _AX = 1990; }

20. What will be the output of the program? #include<stdio.h> void fun(int*, int*); int main() { int i=5, j=2; fun(&i, &j); printf("%d, %d", i, j); return 0; } void fun(int *i, int *j) { *i = *i**i; *j = *j**j; } A.5, 2 B.10, 4 C.2, 5 D.25, 4

21. What will be the output of the program? #include<stdio.h> int reverse(int); int main() { int no=5; A. Print 5, 4, 3, 2, 1 B. reverse(no); C. Print 5, 4, 3, 2, 1, 0 D. return 0; } int reverse(int no) { if(no == 0) return 0; else printf("%d,", no); reverse (no--); }

Print 1, 2, 3, 4, 5 Infinite loop

23. What will be the output of the program? #include<stdio.h> int main() { int a[5] = {5, 1, 15, 20, 25}; int i, j, m; i = ++a[1]; A. 2, 1, 15 B. 1, 2, 5 j = a[1]++; C. 3, 2, 15 D. 2, 3, 20 m = a[i++]; printf("%d, %d, %d", i, j, m); return 0; }

24. What will be the output of the program ? #include<stdio.h> int main() { void fun(int, int[]); int arr[] = {1, 2, 3, 4}; int i; A. 2, 3, 4, 5 fun(4, arr); C. 0, 1, 2, 3 for(i=0; i<4; i++) printf("%d,", arr[i]); return 0; } void fun(int n, int arr[]) { int *p=0; int i=0; while(i++ < n) p = &arr[i]; *p=0; }

B. D.

1, 2, 3, 4 3, 2, 1 0

24. What will be the output of the program ? #include<stdio.h> void fun(int **p); int main() { int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; int *ptr; ptr = &a[0][0]; fun(&ptr); return 0; } void fun(int **p) { printf("%d\n", **p); A.1 B.2 C.3 D.4

26. What will be output of following program? #include<stdio.h> int main() { int a = 320; char *ptr; ptr =( char *)&a; printf("%d ",*ptr); return 0; } (A) 2 (B) 320 (C) 64 (D) Compilation error (E) None of above

26. What will be output of following program? #include<stdio.h> int main() { int i = 3; int *j; int **k; j=&i; k=&j; printf("%u %u %d ",k,*k,**k); return 0; } (A) Address, Address, 3 (B) Address, 3, 3 (C) 3, 3, 3 (D) Compilation error (E) None of above

27. What will be output of following program? #include<stdio.h> int main() { char far *p =(char far *)0x55550005; char far *q =(char far *)0x53332225; *p = 80; (*p)++; printf("%d",*q); return 0; } (A) 80 (B) 81 (C) 82 (D) Compilation error (E) None of above

28. What will be output of following program? #include<stdio.h> #include<string.h> int main() { char *ptr1 = NULL; char *ptr2 = 0; strcpy(ptr1," c"); strcpy(ptr2,"questions"); printf("\n%s %s",ptr1,ptr2); return 0; } (A) c questions (B) c (null) (C) (null) (null) (D) Compilation error (E) None of above

29. What will be output of following program? #include<stdio.h> #include<string.h> int main() { register a = 25; int far *p; p=&a; printf("%d ",*p); return 0; } (A) 25 (B) 4 (D) Compilation error

(C) Address (E) None of above

30. What will be output of following program? #include<stdio.h> int main() { int a = 10; void *p = &a; int *ptr = p; printf("%u",*ptr); return 0; } (A) 10 (B) Address (D) Compilation error

(C) 2 (E) None of above

You might also like