C Language | 10 Minute‐Test 4


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int i = 0, j = 1;

       int *a[] = {&i, &j};

       printf("%d", *a[0]);

       return 0;

   }

 

A.
Compile time error
B.
Undefined behaviour
C.
0
D.
Some garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

2.

Comment on the output of this C code?

#include <stdio.h>

   int main()

   {

       int a = 1;

       switch (a)

       case 1:

           printf("%d", a);

       case 2:

           printf("%d", a);

       case 3:

           printf("%d", a);

       default:

           printf("%d", a);

   }

 

A.
No error, output is 1111
B.
No error, output is 1
C.
Compile time error, no break statements
D.
Compile time error, case label outside switch statement

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

3.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int x = -2;

       x = x >> 1;

       printf("%d\n", x);

   }

 

A.
1
B.
-1
C.
2 ^ 31 – 1 considering int to be 4 bytes
D.
Either b or c

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

4.

What is the output of this C code?

#include <stdio.h>

   int foo();

   int main()

   {

       int i = foo();

   }

   foo()

   {

       printf("2 ");

       return 2;

   }

 

A.
2
B.
Compile time error
C.
Depends on the compiler
D.
Depends on the standard

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

expl

5.

Which is correct with respect to size of the datatypes?

A.
int > char > float
B.
char > int > float
C.
char < int < double
D.
double > char > int

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

char has lesser bytes than int and int has lesser bytes than double in any system

6.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int x = 3, y = 2;

       int z = x << 1 > 5;

       printf("%d\n", z);

   }

 

A.
1
B.
0
C.
3
D.
Compile time error

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

7.

What is output of code given below?

#include <stdio.h>

   int main()

   {

       int i = 0, j = 0;

       while (i < 2)

       {

           l1 : i++;

           while (j < 3)

           {

               printf("Loop\n");

               goto l1;

           }

       }

   }

 

A.
Loop Loop
B.
Compilation error
C.
Loop Loop Loop Loop
D.
Infinite Loop

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

8.

The below two lines are equivalent to
#define C_IO_HEADER
#include C_IO_HEADER

A.
#include
B.
#include"printf"
C.
#include"C_IO_HEADER"
D.
#include

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Since C_IO_HEADER is defined to be , the second line becomes #include, since C_IO_HEADER is replaced with

9.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       void *p;

       int a[4] = {1, 2, 3, 4};

       p = &a[3];

       int *ptr = &a[2];

       int n = (int*)p - ptr;

       printf("%d\n", n);

   }

 

A.
1
B.
Segmentation fault
C.
Compiler error
D.
4

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Size of any type of pointer is 4 on a 32-bit machine.

10.

What is the output of this C code?

    #include <stdio.h>

    int main()

    {

        const int p;

        p = 4;

        printf("p is %d", p);

        return 0;

    }

 

A.
p is 4
B.
Compile time error
C.
Run time error
D.
p is followed by a garbage value

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Since the constant variable has to be declared and defined at the same time, not doing it results in an error.


Submit your test now to view the Results and Statistics with answer explanation.