You are on page 1of 21

C and DATA STRUCTURES

1)What will be the value of z in the end int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; 1)5 2)6 3)10 4)12 2)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? 1)3 2)5 3)7 4)11 3)What will be the output of the following code int a=10,b; b=a++ + ++a; printf("%d,%d,%d,%d",b,a++,a,++a); 1)12,10,11,13 2) 22,10,11,13 3) 22,11,11,11 4) 22,13,13,13 4) What will be the output of the following code snippet? char* myFunc (char *ptr) { ptr += 3; return (ptr); } int main() { char *x, *y; x = "HELLO"; y = myFunc (x); printf ("y = %s \n", y); return 0;

} 1)y = HELLO 2)y = ELLO 3)y = LLO 4)y = LO 5) "My salary was increased by 15%!" Select the statement which will EXACTLY reproduce the line of text above. 1)printf("\"My salary was increased by 15/%\!\"\n"); 2)printf("My salary was increased by 15%!\n"); 3)printf("My salary was increased by 15'%'!\n"); 4)printf("\"My salary was increased by 15%%!\"\n"); 6) What is the difference between a declaration and a definition of a variable? 1)Both can occur multiple times, but a declaration must occur first. 2)There is no difference between them. 3)A definition occurs once, but a declaration may occur many times. 4)A declaration occurs once, but a definition may occur many times. 7) int x[] = { 1, 4, 8, 5, 1, 4 }; int *ptr, y; ptr = x + 4; y = ptr - x; What does y in the sample code above equal? 1) -3 2)0 3)4 4)4 + sizeof( int ) 8) What is the output of the following code snippet? void myFunc (int x) { if (x > 0) myFunc(--x); printf("%d, ", x); } int main() { myFunc(5); return 0;

} 1)1, 2, 3, 4, 5, 5, 2)4, 3, 2, 1, 0, 0, 3)5, 4, 3, 2, 1, 0, 4)0, 0, 1, 2, 3, 4, 9) 11 ^ 5 What does the operation shown above produce? 1)1 2)6 3)8 4) 14 10) What will be printed when the sample code above is executed? int x = 0; for (x=1; x<4; x++); printf("x=%d\n", x); 1)x=0 2)x=1 3)x=3 4)x=4 11) int x = 3; if( x == 2 ); x = 0; if( x == 3 ) x++; else x += 2; What value will x contain when the sample code above is executed? 1) 1 2) 2 3) 3 4) 4 12) int a=5 a*=2+3 What will be the value of a after executing above statement 1)25 2)13 3)30 4)None of these

13) int x = 5; int y = 2; char op = '*'; switch (op) { default : x += 1; case '+' : x += y; case '-' : x -= y; } After the sample code above has been executed, what value will the variable x contain? 1)4 2)5 3)6 4)7 14) x = 3, counter = 0; while ((x-1)) { ++counter; x--; } Referring to the sample code above, what value will the variable counter have when completed? 1)0 2)1 3)2 4)5 15) #include <stdio.h> int i; void increment( int i ) { i++; } int main() { for( i = 0; i < 10; increment( i ) ) { } printf("i=%d\n", i); return 0; } What will happen when the program above is compiled and executed? 1)it will print out: i=9.

2)It will print out: i=10. 3)It will print out: i=11. 4)It will loop indefinitely. 16) 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 17) int x = 0; for ( ; ; ) { if (x++ == 4) break; continue; } printf("x=%d\n", x); What will be printed when the sample code above is executed? 1)x=0 2)x=1 3)x=4 4)x=5

18) #include <stdio.h> 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 19) Consider a circular queue with a size of 5 elements is maintained by an array where FRONT =2 & REAR=3. What is the maximum no. of elements that can be added without deleting any element? 1) 1 2) 2 3) 3 4) 4 20) Double linked list node has____________ 1) 1 INFO & 2 pointers 2) 2 INFO & 2 pointers 3) 2 INFO 1 pointer 4) any no. of INFO & pointers 21) Local Variables in C are stored in 1)Stack 2)Queue 3)Heap 4)Data Segment

22) How many pointer manipulations are needed to delete a node from a doubly linked list 1)1 2)3 3)4 4)2 23) Which of the following is Infix equivalent of the Postfix expression 5 6 2 + * 12 4 / 1) 5*6+2-12/4 2) 5*(6+2)-(12/4) 3) (5*6)+2-(12/4) 4) None of these 24) Which of the following is FALSE with respect to an array? 1) Array size is fixed 2) Arrays can be multidimensional 3) Elements in an array are stored in contiguous memory locations 4) Insertion and Deletion can be done easily on an array compared to a linked list 25) A linear array is 1) An infinite heterogeneous collection of data 2) A finite heterogeneous collection of data 3) A finite homogeneous collection of data 4) None of these 26) Basic unit of a linked list is ____________ 1) A String 2) A Node 3) A Character 4) An Integer 27) Operations possible on a Linked list is 1) Insertion 2) Deletion 3) Searching 4) All of the above 28) Suppose cursor points to a node in a linked list, what statement changes cursor so that it points to the next node? 1)cursor++; 2)cursor-> link++; 3)cursor ->link+= link; 4)cursor = cursor->link;

29) Without ___________function we cannot implement Linked list in C 1)malloc() 2)getnode() 3)free() 4)none 30) Which of the following searching technique can be applied on a Singly linked list? 1)Sequential Search 2)Binary Search 3)Ternary Search 4)None 1)Which of the following is not a fundamental data type 1) int 2) char 3) float 4) double 2).In any C program, main() is always the starting point of execution 1) True 2) False 3) One among the following is not a keyword in C 1)switch 2)case 3)default 4)FILE 4) One of the following is a correct sequence for for statement a)Initialization b)Test condition c)Increment/Decrement 1)c,a,b 2)b,c,a 3)c,a,b 4)a,b,c 5) The argument for switch statement cannot be 1)A float variable 2)An arithmetic expression 3)A character 4)An Integer 6) What will be the output of the following C code

void main() { int x,y=0; if(x=y) printf(X is Equal to Y\n); else printf(X is not Equal to Y\n); } 1)X is Equal to Y 2)X is not Equal to Y 3)Compile Error 4)Runtime Error 7) Format specifier of long double in C is 1) %f 2) %lf 3) %Lf 4) %ld 8) Which of the following CANNOT be used to come out of a loop unconditionally 1) continue 2) break 3) exit 4) goto 9)Arrange the following operators in their increasing order of their precedence a.[] b. / c. + d. = 1) a,b,c,d. 2) d,c,b,a 3) b,c,d,a 4) d,a,b,c. 10) Consider the following statements in C. a) if(x==2){} b) if(2==x){} 1) 2) 3) 4) both the statements are true statement (a) is true, but statement (b) is false both statements are wrong statement (b) is true, but statement (a) is false

11) What will be the output of the following C code

void main() { int x=10; printf(%d%d%d\n,x!=10,x=20,x<30); } 1) 0,1,1 2) 1,1,0; 3) 1,20,1 4) 0,20,1 12) What will be the values of x and y(int variables) with inputs given as 356, 473 respectively for the statement scanf(%2d %2d, &x,&y); 1) 2) 3) 4) x=356 y=47 x=35 y=6 x=35 y=4 x=35 y=47

13) What will be the output of the following program main() { int x, y; x=10; y=10; (x>y)?printf(X is greater ):printf (Y is greater); } 1) 2) 3) 4) Syntax error: Condition not satisfied X is greater Y is greater No output

14) How many xs are printed? void main() { for(i=0,j=10;i<j;i++,j--) printf(x); } 1) 2) 3) 4) 10 5 4 none

15) What will be the output of the following C code #define SQR(X) X*X void main() { printf(%d,SQR(2+3)); } 1)11 2)25 3)35 4)None of the above 16) What would be the result of the following program? main() { char p[]=string; char t; int i,j; for(i=0,j=strlen(p);i<j;i++) { t=p[i]; p[i]=p[j-i]; p[j-i]=t; } printf(%s,p); } 1) string 2) will not print anything 3) gnirts 4) will result in a complication error

17). The size of a Queue is 5, Front = 2 & Rear =2 . What happens if a new element is added to the queue in C language (first element is stored in 0th position)? 1) Front =3, Rear = 2 2) Front = 2, Rear =3 3) Overflow 4)Underflow 18) Overflow condition in a Circular Queue implemented using C is 1)(Rear+1) % n== Front 2)Rear % n == Front 3)Rear - 1 % n == Front

4)None 19) Which of the following operation cannot be applied on a Stack? 1) pop() 2) push() 3) peep() 4) sort() 20) If the Postfix expression is 5 6 2 + * 8 4 / - , then the value of the expression is 1) 23 2) 32 3) 38 4) 42 21) Push operation on a stack _____________ 1) Increases the number of elements present 2) Decreases the number of elements present 3) Doesnt change in the number of elements present 4) Sorts the number of elements present 22) A single linked list node contain_____________ 1) 2 pointers, 1 data 2) 2 pointer 2 data 3) 1 pointer,1 data 4) All the above 23) free () function in C does the following 1) De allocates memory from a node 2) Allocates memory to a node 3) Deletes the element in the node 4) None 24)____ no of pointer manipulations is required for inserting a node in the middle of double linked list 1) 1 2) 2 3) 3 4) 4 25) Queue uses _________Concept 1) LIFO 2) FIFO 3) Both 4) None

26)Which of the following data structure is used for Expression conversion 1)Queue 2)Array 3)Stack 4)graph 27)Which of the following sorting technique is called as tree sorting technique 1)Heapsort 2)Quicksort 3)Merge sort 4)Bubble sort 28)Which of the following sorting technique requires more space in order to sort elements 1)Bubble sort 2)Insertion sort 3)Merge sort 4)Selection sort 29)If there is a singly linked list where insertion and deletion are limited to front end illustrates 1)queue operation 2)stack operation 3)both 1 & 2 4)dqueue operation 30)Which of the following is not a primitive data structure 1)array 2)int 3)real 4)char 1)What will be the output of the following C code #define SQR(X) X*X void main() { int i=4,a,b; a=SQR(i++); b=SQR(++i); printf(%d %d,a,b); } 1)16 64 2)16 25 3)16 36 4)None of the above

2) What will be the output of the following C code void main() { int x=10,y=10,z; z=x-- -y; printf(%d %d %d,x,y,z); } 1)9 10 0 2)10 9 0 3) 10 10 0 4)10 10 -1 3)main() { int arr[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; printf(\n %d,*(*(arr+2)+2)+2); } Considering the above code, what would be the output 1) 9 2) 11 3) 13 4) 10 4) What will be the output of the following C code void main() { char s[10]=Hello; char *p; p=s; printf(%s,++p); } 1)Hello 2)ello 3)Compiler Error 4)None of the above 5) What will be the output of the following C code void main() { char s[10]=Hello; char *p;

p=s; (*p)--; printf(%s,p); } 1)Hello 2)ello 3)Iello 4)Gello 6)What will be the output of the program? main(){ int i,b[]={1,2,3,4,5},*p; p=b; ++*p; printf(%d,*p); p+=2; printf(%d,*p); } 1) 2 3 2) 2 4 3) 3 4 4) 2 5 7) What will be the output of the given program main() { int arr[5]={10,20,30,40,50}; int *p; p=&arr[0]; printf(%d %d,*p++,++*p); } 1) 2) 3) 4) 11 11 20 30 10 20 10 50

8) What will be the output of the following C code? main() { printf(%d\n,sum(5)); } int sum(int n)

{ if(n<1) return n; else return(n+sum(n-1)); } 1) 2) 3) 4) 10 16 14 15

9) One of the following is not a storage class in C 1)auto 2)static 3)extern 4)volatile 10) What will be the output of the following C code main() { int i=10; i=fun((i=fun(i=fun(i)))); printf(%d ,i); } fun(int i) { i++; return(i); }

1)10 2)13 3)14 4)None of the above 11) In ___mode the file is opened from the beginning for both reading and writing 1)a 2)r+ 3)w 4)none 12) If one or more members of a structure are pointers to the same structure, the structure is known as 1) nested structure

2) invalid structure 3) self-referential structure 4) unstructured structure 13) What will be the output of the following C code struct st1 { int a; float b; }s1={10,20.34}; struct st2 { int a; float b; }s2={20,30.34}; void main() { s1=s2; printf(%d %f,s1.a,s1.b); } 1)Compile Error 2)10 20.34 3)20 30.34 4)10 30.34 14) What is the size of q in the following C code. (Assume int takes 2 bytes) union un { struct str { int x; char y; int x,y; }p; }q; 1) 11 2) 7 3) 4 4) 5 15) typedef union ut

{ int i; float f; char s[20]; }ut1; 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'). The size of au is 1) 80 2) 100 3) 130 4) 20

16)Which of the following data structure is used by Recursive programs 1)Queue 2)Stack 3)Array 4)none of these 17)which of the following is a linear data structure 1)Tree 2)Graph 3)Queue 4)All the above 18)Tree is ______________ 1)Primitive 2)Non primitive 3)Non linear 4)Both 2 & 3 19)Which of the following is not a tree traversal technique 1)Inorder 2)preorder 3)postorder 4)Breadth first search 20) In tree construction which is the suitable efficient data structure? 1)array

2)linked list 3)adjacency matrix 4)all the above 21) The process where we allocate memory whenever there is need is called as 1)Dynamic memory allocation 2)Static memory allocation 3)Fixed memory allocation 4)None of the above

22) Choose the correct answer with respect to linked lists 1) Elements are Physically Adjacent 2) Elements are Logically Adjacent 3) Elements are physically as well as logically adjacent 4) None of the 23) The function malloc() returns 1) node pointer 2) void pointer 3) int pointer 4) all the above 24) Which of the following is the postfix equivalent of the given infix expression 2+9/4*5-8 1)294/5*+82)294/5*+83)2945/*+84) None of these 25) Which one of the following is a Prefix Expression? 1)*+abc 2)ab+c/ 3)(a+b)/c 4) None of these 26) Which of the following is preferred by computer for arithmetic expression evaluation? 1)Postfix 2)Prefix 3)Infix 4)all the above 27). __________ NULL pointers are present in a double linked list 1) 1 2) 2 3) 3

4) 4 28) Consider the following pseudo code:

declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty ) { write the stack's top character to the screen pop a character off the stack }
What is written to the screen for the input "carpets"? 1) 2) 3) 4) serc carpets steprac ccaarrppeettss

29) Here is a pseudo code for the algorithm which is supposed to determine whether a sequence of parentheses is balanced: declare a character stack while ( more input is available) { read a character if ( the character is a '(' ) push it on the stack else if ( the character is a ')' and the stack is not empty ) pop a character off the stack else print "unbalanced" and exit } print "balanced"

Which of these unbalanced sequences does the above code think is balanced? 1) ((()) 2) ())(() 3) (()())
4) (()))()

30)The size of a Linear Queue is 5, Front = 2 & Rear =4 . What happens if a new element is added to the queue in C language (first element is stored in 0th position) ? 1) Front =1, Rear = 5 2) Front = 2, Rear =5 3) Overflow 4) Underflow

You might also like