Top Banner
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;
26
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: c and Data Structures

C and DATA STRUCTURES

1)What will be the value of z in the endint z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a;1)52)63)104)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,132) 22,10,11,133) 22,11,11,114) 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;

Page 2: c and Data Structures

}

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)44)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;

Page 3: c and Data Structures

}

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+3What will be the value of a after executing above statement1)252)133)304)None of these

Page 4: c and Data Structures

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.

Page 5: c and Data Structures

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 = 52)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

Page 6: c and Data Structures

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) 12) 23) 34) 4

20) Double linked list node has____________1) 1 INFO & 2 pointers2) 2 INFO & 2 pointers3) 2 INFO 1 pointer4) any no. of INFO & pointers

21) Local Variables in C are stored in1)Stack2)Queue3)Heap4)Data Segment

Page 7: c and Data Structures

22) How many pointer manipulations are needed to delete a node from a doubly linked list1)12)33)44)2

23) Which of the following is Infix equivalent of the Postfix expression 5 6 2 + * 12 4 / - 1) 5*6+2-12/42) 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 fixed2) Arrays can be multidimensional3) 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 data2) A finite heterogeneous collection of data3) A finite homogeneous collection of data4) None of these

26) Basic unit of a linked list is ____________1) A String2) A Node3) A Character4) An Integer

27) Operations possible on a Linked list is1) Insertion2) Deletion3) Searching4) 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;

Page 8: c and Data Structures

29) Without ___________function we cannot implement Linked list in C1)malloc()2)getnode()3)free()4)none

30) Which of the following searching technique can be applied on a Singly linked list?1)Sequential Search2)Binary Search3)Ternary Search4)None

1)Which of the following is not a fundamental data type 1) int2) char3) float4) 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 C1)switch2)case3)default4)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

Page 9: c and Data Structures

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) continue2) break3) exit4) goto

9)Arrange the following operators in their increasing order of their precedencea.[] b. / c. + d. =

1) a,b,c,d.2) d,c,b,a3) b,c,d,a4) d,a,b,c.

10) Consider the following statements in C. a) if(x==2){} b) if(2==x){}

1) both the statements are true2) statement (a) is true, but statement (b) is false3) both statements are wrong4) statement (b) is true, but statement (a) is false

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

Page 10: c and Data Structures

void main() { int x=10;

printf(“%d%d%d\n”,x!=10,x=20,x<30); }1) 0,1,12) 1,1,0;3) 1,20,14) 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) x=356 y=472) x=35 y=63) x=35 y=44) 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) Syntax error: Condition not satisfied2) X is greater3) Y is greater4) No output

14) How many x’s are printed?void main(){ for(i=0,j=10;i<j;i++,j--) printf(“x”);}

1) 102) 53) 44) none

Page 11: c and Data Structures

15) What will be the output of the following C –code

#define SQR(X) X*X void main() { printf(“%d”,SQR(2+3)); }

1)112)253)354)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) string2) will not print anything3) gnirts4) 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 = 22) Front = 2, Rear =33) Overflow4)Underflow

18) Overflow condition in a Circular Queue implemented using C is1)(Rear+1) % n== Front2)Rear % n == Front3)Rear - 1 % n == Front

Page 12: c and Data Structures

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) 232) 323) 384) 42

21) Push operation on a stack _____________1) Increases the number of elements present2) Decreases the number of elements present3) Doesn’t change in the number of elements present4) Sorts the number of elements present

22) A single linked list node contain_____________1) 2 pointers, 1 data 2) 2 pointer 2 data3) 1 pointer,1 data4) 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) 12) 23) 34) 4

25) Queue uses _________Concept1) LIFO2) FIFO3) Both4) None

Page 13: c and Data Structures

26)Which of the following data structure is used for Expression conversion1)Queue2)Array3)Stack4)graph

27)Which of the following sorting technique is called as tree sorting technique1)Heapsort2)Quicksort3)Merge sort4)Bubble sort

28)Which of the following sorting technique requires more space in order to sort elements1)Bubble sort2)Insertion sort3)Merge sort4)Selection sort

29)If there is a singly linked list where insertion and deletion are limited to front end illustrates1)queue operation2)stack operation3)both 1 & 24)dqueue operation

30)Which of the following is not a primitive data structure1)array2)int3)real4)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 642)16 253)16 364)None of the above

Page 14: c and Data Structures

2) What will be the output of the following C codevoid main() { int x=10,y=10,z;

z=x-- -y; printf(“%d %d %d”,x,y,z);}1)9 10 02)10 9 03) 10 10 04)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 output1) 9 2) 11 3) 134) 10

4) What will be the output of the following C codevoid main() { char s[10]=”Hello”; char *p;

p=s;

printf(“%s”,++p);}1)Hello2)ello3)Compiler Error4)None of the above

5) What will be the output of the following C codevoid main() { char s[10]=”Hello”; char *p;

Page 15: c and Data Structures

p=s; (*p)--;

printf(“%s”,p);}1)Hello2)ello3)Iello4)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 32) 2 43) 3 44) 2 5

7) What will be the output of the given programmain(){

int arr[5]={10,20,30,40,50};int *p;p=&arr[0];printf(“%d %d”,*p++,++*p);

}

1) 11 112) 20 303) 10 204) 10 50

8) What will be the output of the following C code?main(){

printf(“%d\n”,sum(5));}int sum(int n)

Page 16: c and Data Structures

{if(n<1) return n;elsereturn(n+sum(n-1));

}1) 102) 163) 144) 15

9) One of the following is not a storage class in C1)auto2)static3)extern4)volatile

10) What will be the output of the following C codemain(){ int i=10; i=fun((i=fun(i=fun(i)))); printf(“%d “,i);}fun(int i){ i++;return(i);}

1)102)133)144)None of the above

11) In ___mode the file is opened from the beginning for both reading and writing1)a2)r+3)w4)none

12) If one or more members of a structure are pointers to the same structure, the structure is known as

1) nested structure

Page 17: c and Data Structures

2) invalid structure3) self-referential structure4) unstructured structure

13) What will be the output of the following C codestruct 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 Error2)10 20.343)20 30.344)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) 112) 73) 44) 5

15) typedef union ut

Page 18: c and Data Structures

{    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’ is1) 802) 1003) 1304) 20

16)Which of the following data structure is used by Recursive programs1)Queue2)Stack3)Array4)none of these

17)which of the following is a linear data structure 1)Tree2)Graph3)Queue4)All the above

18)Tree is ______________1)Primitive2)Non primitive3)Non linear4)Both 2 & 3

19)Which of the following is not a tree traversal technique1)Inorder2)preorder3)postorder4)Breadth first search

20) In tree construction which is the suitable efficient data structure?1)array

Page 19: c and Data Structures

2)linked list3)adjacency matrix4)all the above

21) The process where we allocate memory whenever there is need is called as1)Dynamic memory allocation2)Static memory allocation3)Fixed memory allocation4)None of the above

22) Choose the correct answer with respect to linked lists1) Elements are Physically Adjacent2) Elements are Logically Adjacent3) Elements are physically as well as logically adjacent4) None of the

23) The function malloc() returns 1) node pointer2) void pointer3) int pointer4) all the above

24) Which of the following is the postfix equivalent of the given infix expression 2+9/4*5-81)294/5*+8-2)294/5*+8-3)2945/*+8-4) None of these

25) Which one of the following is a Prefix Expression?1)*+abc2)ab+c/3)(a+b)/c4) None of these

26) Which of the following is preferred by computer for arithmetic expression evaluation?1)Postfix2)Prefix3)Infix4)all the above

27). __________ NULL pointers are present in a double linked list1) 12) 23) 3

Page 20: c and Data Structures

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) serc 2) carpets 3) steprac 4) 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 characterif ( the character is a '(' )

push it on the stackelse if ( the character is a ')' and the stack is not empty )

pop a character off the stackelse

print "unbalanced" and exit } print "balanced"

Page 21: c and Data Structures

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 = 52) Front = 2, Rear =53) Overflow4) Underflow