CDS Q13

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

DATA STRUCTURE & ALGORITHM

C- PROGRAMMING LANGUAGE

1. The following program

#include<stdio.h>
int main ( )
{
int i = 5;
if (i = = 5) return 0;
else printf (“i is not five”);
printf (“over”);
}

results in

(a) a syntax error (b) an execution error


(c) printing of over (d) print nothing

2. The following statements

for (i = 3; i < 15; i +=3)


{
printf (“%d”, i);
++i;
}

will result in the printing of

(a) 36912 (b) 3691215


(c) 3711 (d) 371115

3. Consider the following flow chart

1
Which of the following does not correctly implements the above flow chart?

(a) if (a>b) (b) if (a<=b)


if (b>c) if (b>c)
a=1 a=1
else if (c>d) else if (c<=d)
b=2 b=2

(c) if (a>b) (d) if (a <=b)


; ;
else if (b>c) else if (b>c)
a=1 a = 1;
else if (c<=d) else if (c>d)
b=2 ;
else b = 2

4. Consider the following program

#include<stdio.h>
main ( )
{
int x = 2, y = 2;
if (x<y) return (x = x+y);
else printf (“z1”);
printf (“z1”);
printf (“z2”);
}

Choose the correct statements

(a) The output is z2 (b) The output is z1z1z2


(c) This will result in compilation error (d) None of the above

2
5. Choose the False statements:

(a) The scope of a macro definition need not be the entire program
(b) The scope of a macro definition extends from the point of definition to the end of the file
(c) A macro definition may go beyond a line
(d) None of the above

6. Consider the following program fragment

if (a>b)
printf (“a>b”)
else
printf (“else part”);
printf (“a<=b”);

then a <= b

will be printed if

(a) a > b (b) a < b


(c) a = = b (d) All of the above

7. Consider the two declarations

void *voidPtr;
char *charPtr;

Which of the following assignments are syntactically Correct?

(a) charPtr = voidPtr (b) voidPtr = charPtr


(c) *charPtr = voidPtr (d) *voidPtr = *charPtr

8. The output of the following program is

#include<stdio.h>
main ( )
3
{
static int x[ ] = {1, 2, 3, 4, 5, 6, 7, 8};
inti ;
for (i = 2; i<6; ++i)
x [x[i]] = x [i];
for (i = 0; i<8; ++i)
printf (“%d”, x [i]);
}

(a) 12335578 (b) 12345678


(c) 12354678 (d) 87654321

9. The following program

main ( )
{
static char [3] [4] = {“abcd”, “mnop”, “fghi”};
putchar (**a);
}

(a) will not compile successfully (b) results in run-time error


(c) prints garbage (d) none of these

10. The following program

#include<stdio.h>

main ( )
{
int abc ( );
abc ( );
(*abc) ( );
}

int abc ( )

4
{ printf (“come”);}

(a) results in a compilation error (b) prints come come


(c) results in a run-time error (d) prints come

11. The time required to search an element in a linked list of length n is

(a) O(log2 n) (b) O(1)


(c) O(n) (d) O(n2)

12. Consider the declaration

char x [ ] = “SUCCESS”;
char *y = “SUCCESS”;

Pick the correct answers.

(a) The output of puts (x) and puts (y) will be different
(b) The output of puts (x) and puts (y) will be same
(c) The output of puts (y) is implementation dependent
(d) None of the above comments are true

13. Use of macro instead of function is recommended.

(a) when one wants to reduce the execution time


(b) when there is a loop with a function call inside
(c) when a function is called in many places in a program
(d) In (a) and (b) above

14. For loop in a C-program, if the condition is missing

(a) it is assumed to be present and taken to be false


(b) it is assumed to be present and taken to be true
(c) it result in a syntax error
(d) execution will be terminated abruptly

5
15. Consider the following statements.

#define hypotenuse (a, b) sqrt (a* a+b *b);


The macro-call hypotenuse (a+2, b+3);

(a) Finds the hypotenuse of a triangle with sides a+2 and b+3
(b) Finds the square root of (a+2)2 + (b+3)2
(c) Finds the square root of 3*a + 4*b + 5
(d) Is invalid

16. For ‘C’ programming language

(a) constant expressions are evaluated at compile time


(b) size of array should be known at compile time
(c) strings constants can be concatenated at compile time
(d) all of these

17. Consider the declarations:

char first (int(*) (char, float));


int second (char, float);

Which of the following function invocation is valid?

(a) first (*second) (b) first (&second);


(c) first (second) (d) none of these

18. The output of the following program

main ( )
{
int a = 1, b = 2, c = 3;
printf (“%d”, a+ = (a+ = 3, 5, a));
}

will be

(a) 12 (b) 6
(c) 9 (d) 8

You might also like