C Language | 10 Minute‐Test 5


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)[1]);

       return 0;

   }

 

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

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

None.

2.

Switch statement accepts.

A.
char
B.
int
C.
long
D.
All of the mentioned

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

   {

       if (~0 == 1)

           printf("yes\n");

       else

           printf("no\n");

   }

 

A.
yes
B.
no
C.
Compile time error
D.
Undefined

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

None.

4.

What is the output of this C code?

#include <stdio.h>

   double foo();

   int main()

   {

       foo();

       return 0;

   }

   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 B

Explanation:

None.

5.

What is the output of the following C code(on a 64 bit machine)?

#include <stdio.h>

   union Sti

   {

       int nu;

       char m;

   };

   int main()

   {

       union Sti s;

       printf("%d", sizeof(s));

       return 0;

   }

 

A.
8
B.
5
C.
9
D.
4

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.

6.

What is the output of this C code?

#include <stdio.h>

   int main()

   {

       int x = 3, y = 2;

       int z = x /= y %= 2;

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

   }

 

A.
Compile time error
B.
1
C.
Floating point exception
D.
Segmentation fault

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

None.

7.

What is the output of code given below?

#include <stdio.h>

   int main()

   {

       int i = 0, j = 0;

       while (l1: i < 2)

       {

           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 B

Explanation:

None.

8.

What is the output of this C code?

#include <stdio.h>

   #include "printf"

   void main()

   {

       printf("hello");

   }

 

A.
hello
B.
Error
C.
Depends on compiler
D.
Varies

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

9.

What is the output of this C code?

    #include <stdio.h>

    int main()

    {

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

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

        int n = &b[3] - &a[2];

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

    }

 

A.
-3
B.
5
C.
Compiler error
D.
4

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

None.

10.

Comment on the output of this C code?

    #include <stdio.h>

    void main()

    {

        int k = 4;

        int *const p = &k;

        int r = 3;

        p = &r;

        printf("%d", p);

    }

 

A.
Address of k
B.
Address of r
C.
Compile time error
D.
Adress of k + address of r

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.


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