Sei sulla pagina 1di 12

C Test

PAPER - 1

1) int prime[7]= {2, 3 ,5, 7, 11, 13}; The size of the array prime assuming int variables to occupy 2 bytes is a) b) c) d) 14 12 6 None of these

2) a = 100; b = 5; c = a << b << 3; Assuming the type of all variables to be int the value stored in c is a) b) c) d) 3) The output of the program : #include <stdio.h> int e=4; struct x {int a; int b;}; struct x c = {3,4}; struct x d = {5,6}; void main(){ c.a = c.b + d.a; e = d.a + c.b; printf("%d\n",e);} 7 25600 5 12800

a) b) c) d)

9 13 10 8

4) The output of the program : #include <stdio.h> void main(){ int a=1, b=2, c=3; a = b << c; printf("%d\n",a);} a) b) c) d) Q 5 Q7 5 1 6 8 5) The counter-postfix notation is a) 4972683051 b) 3794268501 c) 1058624973 d) 3510726894 16 32 8 2 3 7 0 4 2 9

6) The infix notation a) 3510726894 b) 1503862794 c) 3571029648 d) None of these 7) The corresponding binary search tree in infix notation is a) Binary search tree cannot be created as the elements are not sorted when traversed in any order. b) 0123456789 c) 1503862794 d) None of these

8)Given the following declaration; FILE *ifp; Which of the following would not open the file input.dat for input in text mode? a) b) c) d) ifp = fopen (input.dat, r); ifp = fopen (input.dat, r+); ifp = fopen (input.dat, rb); ifp = fopen (input.dat, rt);

Q9 Q12 typedef union ut { int I; float f; char s [20]; }; ut u, *pu, au [5];

(Assume that an int is '2 bytes', float is '4 bytes', char is '1 byte' and pointer is '4 bytes'). 9) The size of ut is a) 20 b) 21 c) Trying to find the size results in an error d) 26 10) The size of a) b) c) d) u is 21 22 20 19

11) The size of pu is a) 20 b) 4 c) 26 d) Cannot be decided as it is compiler dependent 12) The size of au is a) 80 b) 100 c) 130 d) 20 13) The output of the program : #include <stdio.h> void main(){ char c[ ] = "Hi_mom"; char *cp = c; printf("%d\n",sizeof(cp));} a) 6

b) 5 c) 4 d) None of these as the sizeof function flags an error 14) p is a 15-element array of pointers to functions; each function accepts an argument which is a pointer to a float and returns a pointer to a double. The declaration used is a) double (**p[15]) (float []); b) double *(*p[15])(float *a); c) double *( (*p)[15]) *(float a); d) double (*p[]) *(float *a); 15) Assume the size of int to be 2 bytes and the program is run on a 486 machine register int a = 10; The size of a a) b) c) d) is 2 as int is assumed to occupy 2 bytes Error ! As it is illegal to find the size of a register variable is 4 as registers of 486 are 32bit in length Compiler dependent

PAPER 2 Assume char occupies 1 byte, int 2 bytes, float 4 bytes and double 8 bytes unless explicitly stated. 1) What is the number of bytes occupies by the array Arr declared as double Arr [20] [5] [6]; a) 3040 b) 4800 c) 2400

d) 1200 2) Which one of the following with respect to the following declarations is true : char strl [5] = "ABCD"; char *str2 = "ABCD"; a) b) c) d) size of str1 = size of str2 str1[5] = \0; *(str2+4) = \0; All are false

3) The output of the program : #include <stdio.h> void main(){ int a=1, b=2, c=3, d=4; char ca[80]; a= sprintf(ca,"%1d %1d %1d\n",b,c,d); printf("%d\n",a);} a) 2 3 4 1 b) 2 3 4 6 c) 6 d) None of the above

4) The output of the program :

#include <stdio.h> void main(){ int a=1, b=2, c=3; a = b << c; printf("%d\n",a);} a) b) c) d) 2 8 4 16

5) The output of the program : #include <stdio.h> void main(){ int a=1, b=5, c=3; a = b ^ c; printf("%d\n",a);} a) b) c) d) 6) float a = 3.56; void main() { 5 7 1 None of the above

float b; b = a % 3; printf (%f,b); } a) b) c) d) 0.56 Results in a compiler error Results in a linker error Depends on the compiler

7) Sparse matrix is a) A representation of a matrix containing more zero elements b ) A matrix wherein the number of non-zero elements is very less c) A representation of a matrix containing only zero elements d) A singular matrix 8) The sorting technique with the best efficiency when the no. of elements is large and the no. of digits in each element is quite less is a) Quick sort b) Merge sort c) Bubble sort d) Radix sort 9) The output of the program is #include <stdio.h> #include <string.h> void main(){ char c[] = "Hi folks"; char d[] = "Hi folks"; printf("%d\n",strcmp(c,d));} a) 0 b) Some non-zero value c) Declaration error

d) None of the above

10) The output of the program : #include <stdio.h> int play(int x, int y){ int a; if (y == 0) return 1; if (y % 2 == 0) return (play (x,y/2)*play(x,y/2)); return (x*play(x,y/2)*play(x,y/2)); } void main(){ int a, b=8; a = play(3, b); printf("%d\n",a);} a) b) c) d) Goes to an infinite loop 81 2187 6561

11)

The value of i when the loop terminates

int i,j; for (i = 0,j = 0; i <= 10, j < 5; i++, j+=2); a) b) c) d) 3 11 4 10

12) The output of the following program : #include <stdio.h> void main(void){ int a=2; switch (a){ case 0:a=a+2; case 1:a=a+4; case 2:a=a+8; case 3: a=a+6; default: a=a+32;} printf("%d\n",a);} a) 10 b) Error because of absence of break statement at the end of case structure c) 48 d) 14

13) Assuming i to be an integer with the value 10 the output of the following program statement printf ( %d %d %d, ++i, i++, i); is a) b) c) d) 12 10 10 11 11 12 10 12 12 11 12 12

14) a) b) c) d) 15)

Function xxxx should have a prototype errors are produced during Run-time Compile Time Link Time While preprocessing The output of the program

void main() { char str[5] = abc; printf (%s,&0[str]); } a) b) c) d) abc Error Unpredicatable output bc

Answers Paper 1 1) a 2) b 3) a 4) a 5) b 6) b 7) b 8) c 9) a 10) 11) 12) 13) 14) 15)

c b b c b a

Paper 2 1) b 2) c 3) c 4) d 5) d 6) b 7) a 8) d 9) a 10) 11) 12) 13) 14) 15) a

d a c a c

Potrebbero piacerti anche