26
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?

C and DATA STRUCTURES

Embed Size (px)

Citation preview

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;

Page 2: C and DATA STRUCTURES

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

Page 3: C and DATA STRUCTURES

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+3What will be the value of a after executing above statement

Page 4: C and DATA STRUCTURES

1)252)133)304)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;

Page 5: C and DATA STRUCTURES

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

Page 6: C and DATA STRUCTURES

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

Page 7: C and DATA STRUCTURES

1)Stack2)Queue3)Heap4)Data Segment

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/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 is4)      Insertion5)      Deletion6)      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++;

Page 8: C and DATA STRUCTURES

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

Page 9: C and DATA STRUCTURES

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 5)      ‘%f’6)      ‘%lf’7)      ‘%Lf’8)      ‘%ld’

8) Which of the following CANNOT  be  used to come out of a loop unconditionally 5)      continue6)      break7)      exit8)      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){}

5)      both the statements are true6)      statement (a) is true, but statement (b) is false7)      both statements are wrong8)      statement (b) is true, but statement (a) is false

Page 10: C and DATA STRUCTURES

11) What will be the output of the following C codevoid 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);

5)      x=356 y=476)      x=35 y=67)      x=35 y=48)      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”);                    }

5)      Syntax error: Condition not satisfied6)      X is greater7)      Y is greater8)      No output

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

5)      106)      5

Page 11: C and DATA STRUCTURES

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

}5)      string6)      will not print anything7)      gnirts8)      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  is1)(Rear+1) % n== Front

Page 12: C and DATA STRUCTURES

2)Rear % n == Front3)Rear - 1 % n == Front4)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) Doesn’t 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 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) 1                2) 2                3) 3                4) 4

25) Queue uses _________Concept                1) LIFO                2) FIFO                3) Both

Page 13: C and DATA STRUCTURES

                4) None

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 25

Page 14: C and DATA STRUCTURES

3)16 364)None of the above

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”;

Page 15: C and DATA STRUCTURES

    char *p;

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

5)      2 36)      2 47)      3 48)      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);}

5)      11 116)      20 307)      10 208)      10 50

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

Page 16: C and DATA STRUCTURES

}int sum(int n){        if(n<1) return n;        else        return(n+sum(n-1));}

4)      105)      166)      14

4)  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

Page 17: C and DATA STRUCTURES

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

5)      nested structure6)      invalid structure7)      self-referential structure8)      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;5)  11           6)  77)  48)  5

Page 18: C and DATA STRUCTURES

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’ is5)      806)      1007)      1308)      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)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

Page 19: C and DATA STRUCTURES

20) In tree construction which is the suitable efficient data structure?1)array2)linked list3)adjacency matrix4)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

5)      Elements are Physically Adjacent6)      Elements are Logically Adjacent7)      Elements are physically as well as logically adjacent8)      None of the

23) The function malloc()  returns 5)      node pointer6)      void pointer7)      int pointer8)      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 list                1) 1                2) 2

Page 20: C and DATA STRUCTURES

                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"?

5)      serc 6)      carpets 7)      steprac 8)      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?

4)      ((()) 5)      ())(() 6)      (()())

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