c and data structure

7
T: 2H 1 C and Data Structure 1. The operator & is used for 1. Bitwise AND 2. Bitwise OR 3. Logical AND 4. Logical OR 2. Built-in data structures in „C‟ are 1. Arrays 2. Structures 3. Files 4. All of the above 3 .The size of a character variable in „C‟ is 1. 4 byte 2. 8 bytes 3. 16 bytes 4. None of the above 4. What is the output of the following program segment? #include<stdio.h> main() { int i=10, m=10; clrscr(); printf(“%d”, i>m?i*i:m/m,20); getch(); } 1. 20 2. 1 3. 120 4. 100 20 5. Data type of the controlling statement of a SWITCH statement cannot of the type: 1. int 2. char 3. short 4. float 6. How long the following loop runs: for (x=0; x=3; x++) 1. Three time 2. Four times 3. Forever 4. Never 7. An expression contains assignment, relational and arithmetic operators. If parentheses are not specified, the order of evaluation of the operators would be: 1. assignment, arithmetic, relational 2. relational, arithmetic, assignment 3. assignment, relational, arithmetic 4. arithmetic, relational, assignment 8. The CONTINUE statement cannot be used with 1. for 2. switch 3. do 4. while 9. Output of the following program will be: main( ) { int a [ ] = {1, 2, 9, 8, 6, 3, 5, 7, 8, 9}; int *p = a+1; int *q = a+6; printf (“\n%d”, q-p); MM:50

Upload: prabhatjon

Post on 11-Nov-2014

2.817 views

Category:

Education


0 download

DESCRIPTION

for more CDAC CAT or DAC Examination guess and sample paper please visit http://cdacguru.wordpress.com

TRANSCRIPT

Page 1: C and data structure

T: 2H

1

C and Data Structure

1. The operator & is used for

1. Bitwise AND

2. Bitwise OR

3. Logical AND

4. Logical OR

2. Built-in data structures in „C‟ are

1. Arrays

2. Structures

3. Files

4. All of the above

3 .The size of a character variable in „C‟ is

1. 4 byte

2. 8 bytes

3. 16 bytes

4. None of the above

4. What is the output of the following program segment?

#include<stdio.h>

main()

{

int i=10, m=10;

clrscr();

printf(“%d”, i>m?i*i:m/m,20);

getch();

}

1. 20

2. 1

3. 120

4. 100 20

5. Data type of the controlling statement of a SWITCH statement cannot of the type:

1. int

2. char

3. short

4. float

6. How long the following loop runs:

for (x=0; x=3; x++)

1. Three time

2. Four times

3. Forever

4. Never

7. An expression contains assignment, relational and arithmetic operators. If parentheses

are not specified, the order of evaluation of the operators would be:

1. assignment, arithmetic, relational

2. relational, arithmetic, assignment

3. assignment, relational, arithmetic

4. arithmetic, relational, assignment

8. The CONTINUE statement cannot be used with

1. for

2. switch

3. do

4. while

9. Output of the following program will be:

main( )

{

int a [ ] = {1, 2, 9, 8, 6, 3, 5, 7, 8, 9};

int *p = a+1;

int *q = a+6;

printf (“\n%d”, q-p);

MM:50

Page 2: C and data structure

2

}

1. 9

2. 5

3. 2

4. None of the above

10. Size of the following union (assume size of int=2; size of float=4 and size of char = 1):

union Jabb

{

int a;

float b;

char c;

};

1. 2

2. 4

3. 1

4. 7

11. int z, x=5, y=-10, a=4, b=2;

z=x++ - --y * b / a;

What will be the final value of z?

1. 5

2. 6

3. 10

4. 11

12. With every use of memory allocation function, what function should be used to release

allocated memory which is no longer needed?

1. dropmem( ) 2. dealloc( )

3. release( ) 4. free( )

13. int warr[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

What will be the value of warr[2][1][0]?

1. 5

2. 7

3. 9

4. 11

14. char *ptr;

char myString[ ] = “abcdefg”;

ptr = myString;

ptr += 5;

The pointer ptr points to which string?

1. fg

2. efg

3. defg

4. cdefg

15. Suppose that x is initialized as:

short int x; /* assume x is 16 bits in size */

What is the maximum number that can be printed using printf (“%d\n”, x),

1. 127

2. 128

3. 255

4. 32,767

16. When applied to a variable, what does the unary “&” operator yield?

1. The variable‟s address

2. The variable‟s right value

3. The variable‟s binary form

4. The variable‟s value

Page 3: C and data structure

3

17. How is a variable accessed from another file?

1. via the extern specifier.

2. via the auto specifier.

3. via the global specifier.

4. via the pointer specifier.

18. What does the following function print?

func(int i)

{if(i%2) return 0;

else return 1;}

main( )

{

int=3;

i=func(i);

i=func(i);

printf(“%d”, i);

}

1. 3

2. 1

3. 0

4. 2

19. Given the piece of code

int a[50];

int *pa;

pa=a;

To access the 6th

element of the array which of the following is incorrect?

1. *(a+5)

2. a[5]

3. pa[5]

4. *(*pa + 5)

20. Regarding the scope of the variables; identify the incorrect statement:

1. automatic variables are automatically initialized to 0

2. static variables are automatically initialized to 0

3. the address of a register variable is not accessible

4. static variables cannot be initialized with any expression

21. Given the following code fragment:

void main(voi4.

{

char x = „\0‟;

char n = „N‟;

printf(“%u” ”%s\n”, &n, &n);

}

What will be the result of execution?

1. ddddd N ( where d represents any digit)

2. 78 N

3. 78 garbage

4. compilation error

22. Given the following code fragment:

int main(voi4.

{

int raw[20], i, sum=0;

int *p = raw;

for (i=0; i < 20; i++)

Page 4: C and data structure

4

*(p+i) = I;

for(i=0; i < 20; I += sizeof(int))

sum += *(p+i)

printf(“sum = %d\n”, sum);

return();

}

What will be the result of execution?

1. sum = 10

2. sum = 40

3. sum = 60

4. sum = 190

23. What is the missing statement in the following function which copies string x into string y

void strcpy( char *x, char *y)

{

while (*y != „\0‟)

………………… /* missing stament */

*x = „\0‟;

}

1. x = y

2. *x++ = *y++

3. (*x)++ = (*y)++

4. none of the above

24. Consider the following program,

main( )

{

int x = 49;

for(;x;)

x--;

printf(“%d\n”, x);

}

the output of the program will be

1. 49

2. 0

3. -49

4. none of the above

25. # define dp(e) printf(#e “ = %d\n”,e)

main( )

{

int x =3, y = 2;

dp(x/y)

}

What will be the output of the program?

1. prints x/y = 1

2. prints #e = 1. 5

3. prints #x/y = 1

4. none of the above

26 . Assume that i, j and k are integer variables and their values are 8, 5 and 0 respectively.

What will be the values of variables i and k after executing the following expressions?

k = ( j > 5) ? ( i < 5) ? i-j: j-i: k-j;

i -= (k) ? (i) ? (j): (i): (k);

1. -3 and 3

2. 3 and -5

3. 3 and -3

4. -5 and 3

Page 5: C and data structure

5

27. The && and | | operators

1. compare two numeric values

2. combine two numeric values

3. compare two boolean values

4. none of the above

28. An external variable is one

1. Which resides in the memory till the end of the program

2. Which is globally accessible by all functions

3. Which is declared outside the body of any function

4. All of the above

29. Find the error in the following program:

main( )

{

int m;

char g;

switch(m)

{

case 5 : grade=”P”;break;

case 2 : grade=”Q”;break;

case 2 : grade=”R”;break;

default : grade=”S”;break;

}

}

1. No two labels may be identical

2. switch statement cannot have more than three labels

3. case label cannot be numbers

4. none of the above

30. Consider the following program:

main( )

{

char *k=”xyz;

f(k);

printf(“%s\n”,k);

}

f(char *k)

{ k = malloc(4); strcpy(k, “pq”); }

What will be the output?

1. pq

2. xyz

3. syntax error

4. none of the above

31. Time complexity of insertion sort algorithm in the best case is

1. O(n)

2. O(n log2 n)

3. O(n2)

4. none of the above

32. In linked list representation, a node contains at least

1. node address field, data field

2. node number, data field

3. next address field, information field

4. none of the above

Page 6: C and data structure

6

33. Which of the following statements are true:

1. binary search is always better than sequential search.

2. binary search is better than sequential search when

number of elements is small.

3. binary search is better than sequential search when

number of elements is very large.

4. binary search is always inferior to sequential search.

34 In an 16-bit computer, 30 digit integer can be stored in

1. an integer variable

2. floating point variable

3. a circular list

4. none of the above

35 A stack can be used to

1. allocate resources by the operating system

2. to schedule jobs on round-robin basis

3. process procedure call in a program

4. none of the above

36. An ordered set of items from which items may be deleted at either end and into which

items may be inserted at either end is called.

1. Queue

2. Stack

3. Heap

4. Dequeue

37. The property of hash function is that

1. it minimizes the rate of overflow

2. it preserves the order of key values.

3. it minimizes number of collisions.

4. none of the above.

38. The number of comparisons needed to merge-sort a list of n elements is

1. O(n log n)

2. O(n log log n)

3. O(n)

4. O(n log n2 )

39. In the text of the divide and conquer algorithm must contain at least

1. One recursive call

2. Two recursive calls

3. Either one or zero calls

4. None of the above

40. In a stack, top=0 denotes that

1. stack is empty

2. stack is full

3. top has no element

4. none of the above

41. The correct increasing order of magnitude of computing time is-

1. O(1) < O(logn) < O(n) < O(n logn) < O(n2) < O(n

3) < O(2

n)

2. O(2n) < O(n

3) < O(n

2) < O(n logn) < O(n) < O(logn) O(1)

3. O(logn) < O(n logn) < O(n) < O(n2) < O(n

3) < O(2

n) < O(1)

4. None of the above

42. Suppose the union is declared like

union

{

float x;

Page 7: C and data structure

7

char c[10];

int y;

}num;

Assuming that float requires 4 bytes, char requires 1 byte and int requires 2 bytes, the memory

space used by the variable num is

1. 16 bytes

2. 10 bytes

3. 4 bytes

4. 7 bytes

43. Which data structure is implemented in automatic variable declaration?

1. Queue

2. Stack

3. Heap

4. Graph

44. If j=2, m=1, x=3, y=4. What is the value of the expression j++ = = m = = y * x

1. 0

2. 1

3. 2

4. 3

45. Which of the following data structure may give overflow error, even though the current number

of elements in it, is less than its size

1. simple queue

2. circular queue

3. stack

4. none of the above

46. Which one is not correct?

1. Pointers are used for dynamically allocating memory.

2. Dynamic memory allocation is preferred when storage requirement is not predictable.

3. Data access in dynamically allocated storage is faster than static allocated storage.

4. None of the above

47. Which of the following cannot be performed recursively?

1. Binary Search

2. Quick Sort

3. Depth First Search

4. None of the above

48. “p” is a pointer to the structure. A member “mem” of that structure is referenced by

1. *p.mem

2. (*p).mem

3. *(p.mem)

4. None of the above

49. If the file contains data (61, 41, 91, 11) then the most suitable sorting technique is–

1. Quick sort

2. Radix sort

3. Insertion sort

4. None of the above

50. If there are total n nodes, then memory compaction requires

1

. O (log2 n) steps

2. O (n) steps

3. O (n2) steps

4. None of the above