C Programming Questions and Answers – Bit-fields – 1

«
»
This section on C programming interview questions and answers focuses on “Bit-fields”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming interview questions on “Bit-fields” along with answers, explanations and/or solutions:

1. What is the correct syntax to initialize bit-fields in an structure?
a)

advertisement
    struct temp
    {
        unsigned int a : 1;
    }s;

b)

advertisement
advertisement
    struct temp
    {
        unsigned int a = 1;
    }s;

c)

advertisement
    struct temp
    {
        unsigned float a : 1;
    }s;

d) None of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement

2. Which of the following data types are accepted while declaring bit-fields?
a) char
b) float
c) double
d) none of the mentioned
View Answer

Answer: a
Explanation: None.

3. Which of the following reduces the size of a structure?
a) union
b) bit-fields
c) malloc
d) none of the mentioned
View Answer

Answer: b
Explanation: None.
advertisement

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

a) 4
b) 8
c) 12
d) 32
View Answer

Answer: c
Explanation: None.

5. Calculate the % of memory saved when bit-fields are used for the following C structure as compared to with-out use of bit-fields for the same structure? (Assuming size of int = 4)

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

a) 25%
b) 33.3%
c) 50%
d) 75%
View Answer

Answer: d
Explanation: None.

6. In the following declaration of bit-fields, the constant-expression specifies __________

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

a) The width of the field in bits
b) Nothing
c) The width of the field in bytes
d) Error
View Answer

Answer: a
Explanation: None.

7. In the following declaration of bit-fields, the constant-expression must be __________

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

a) Any type
b) Nothing
c) Integer value
d) Nonnegative integer value
View Answer

Answer: d
Explanation: None.

8. Which of the following is not allowed?
a) Arrays of bit fields
b) Pointers to bit fields
c) Functions returning bit fields
d) None of the mentioned
View Answer

Answer: d
Explanation: None.

9. Bit fields can only be declared as part of a structure.
a) false
b) true
c) Nothing
d) Varies
View Answer

Answer: b
Explanation: None.

10. What is the order for the following C declarations?

    short a : 17;
    int long y : 33;

a) Legal, legal
b) Legal, illegal
c) Illegal, illegal
d) Illegal, legal
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter