Log In Register

Units


Bit-fields - Questions and Answers

 

Practice these Bit-fields under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Bit-fields for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Bit-fields of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Bit-fields.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Bit-fields under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Bit-fields topic of C Programming:

 

1.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union u
  3.     {
  4.         struct
  5.         {
  6.             unsigned char x : 2;
  7.             unsigned int y : 2;
  8.         }p;
  9.         int x;
  10.     };
  11.     int main()
  12.     {
  13.         union u u.p.x = 2;
  14.         printf("%d\n", u.p.x);
  15.     }

Answer: Option B

Explanation:

2.

Which of the following reduces the size of a structure?

Answer: Option C

Explanation:

3.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         char x : 2;
  5.         int y : 2;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p;
  10.         p.x = 2;
  11.         p.y = 1;
  12.         p.x = p.x & p.y;
  13.         printf("%d\n", p.x);
  14.     }

Answer: Option D

Explanation:

4.

Calculate the % of memory saved when bit-fields are used for the following structure.?
    (Assuming size of int = 4, calculate the % using the memory that would be occupied without     bit-fields)

  1.     struct temp
  2.     {
  3.         int a : 1;
  4.         int b : 2;
  5.         int c : 4;
  6.         int d : 4;
  7.     }s;

Answer: Option A

Explanation:

5.

The following declarations in order are

    short a : 17;
    int long y : 33;

Answer: Option B

Explanation:

6.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union u
  3.     {
  4.         struct p
  5.         {
  6.             unsigned char x : 2;
  7.             unsigned int y : 2;
  8.         };
  9.         int x;
  10.     };
  11.     int main()
  12.     {
  13.         union u u;
  14.         u.p.x = 2;
  15.         printf("%d\n", u.p.x);
  16.     }

Answer: Option C

Explanation:

7.

Which of the following is not allowed?

Answer: Option D

Explanation:

8.

In the declaration of bit-fields,

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression
    The constant-expression specifies

Answer: Option D

Explanation:

9.

For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?

  1.     struct temp
  2.     {
  3.         int a : 13;
  4.         int b : 8;
  5.         int c : x;
  6.     }s;

Answer: Option B

Explanation:

10.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     union u
  3.     {
  4.         struct
  5.         {
  6.             unsigned char x : 2;
  7.             unsigned int y : 2;
  8.         }p;
  9.         int x;
  10.     };
  11.     int main()
  12.     {
  13.         union u u.p = {2};
  14.         printf("%d\n", u.p.x);
  15.     }

Answer: Option B

Explanation:

11.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         unsigned int x : 1;
  5.         unsigned int y : 1;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p;
  10.         p.x = 1;
  11.         p.y = 2;
  12.         printf("%d\n", p.y);
  13.     }

Answer: Option B

Explanation:

12.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         unsigned int x : 7;
  5.         unsigned int y : 2;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p;
  10.         p.x = 110;
  11.         p.y = 2;
  12.         printf("%d\n", p.x);
  13.     }

Answer: Option C

Explanation:

13.

Bit fields can only be declared as part of a structure.

Answer: Option C

Explanation:

14.

Which of the following data types are accepted while declaring bit-fields?

Answer: Option C

Explanation:

15.

In the declaration of bit-fields,

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression
    The constant-expression must be

Answer: Option A

Explanation: