C- Programming Practice Questions for GATE Computer Science



1. Consider the following program

main ( )
{
int i = 5;
if (i = = 5) return;
else printf “i is not five”);
printf (“over”);
}

results in

(a) a syntax error (b) an execution error
(c) printing of over (d) printing anything

Solution: Option (d)

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

Solution: Option (c)

3. The possible output of printf (“%d %d”, wer, wer+1); is

(a) 262262 (b) 262263
(c) 262265 (d) 262266

Solution: Option (d)

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

Solution: Option (d)

5. The following program

main ( )

{
int abc ( );
abc ( );
(*abc) ( );
}
int abc ( )
{ printf (“come”);}

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

Solution: Option (b)

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

Solution: Option (c)

7. A possible output of the following program fragment

static cahr wer [ ] [5] = {“harmot”, “merli”, “axari”);
printf ({“%d %d”, wer, wer [0], &wer [0] [0]); is

(a) 262164 262165 262166 (b) 2616 262164 262165
(c) 262164 262164 262164 (d) 262164 262165 262165

Solution: Option (c)

8. 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

Solution: Option (b)

9. 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

Solution: Option (d)

10. 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

Solution: Option (b)

                                             
gate study material for computer science

11. 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

Solution: Option (c)

12.Consider the following program

main ( )
{
int x = 2, y = 2;
if (x
else printf (“z1”);
printf (“z1”);
printf (“z2”);
}

Choose the correct statements

(a) The output is z2 (b) The output is z1z2
(c) This will result in compilation error (d) None of the above

Solution: Option (b)

13.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

Solution: Option (d)

14.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

Solution: Option (d)

15.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

Solution: Option (b)

16.The output of the following program is

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

(a) 12335578 (b) 12345678
(c) 12354678 (d) 87654321

Solution: Option (a)


17. 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

Solution: Option (d)

18. 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

Solution: Option (c)

19. 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


Solution: Option (d)


Keywords: C Programming Multiple Choice Questions and Answers, C Multiple Choice Questions and Answer,C Programming Online Quiz,C Multiple Choice Questions