Interview Questions and Answers :: Broadcom Ltd
Home > Experience Archives > Broadcom Ltd > Interview Question Set 2 > Discussion
11. Declare 1 bit variable and print it.
Answer:
typedef struct size_t
{
unsigned x:1;
} size_1;
Where you have told the compiler that you'll only be using one bit of x.
But due to structure packing arrangements (the C standard is intentionally flexible in order that compilers can optimize according to the machine architecture), it may well turn out that this still occupies as much space in memory as a regular unsigned and an array of size_1 doesn't have to be bitwise contiguous.
Generally, the smallest addressable chunk of data in C is a byte. You can not have a pointer to a bit, so you can not declare a variable of 1 bit size, But above can be one way to have 1 bit size.
Amit
30 Aug, 2018 12:33 AM
typedef struct size_t
{
unsigned x:1;
} size_1;
Where you have told the compiler that you'll only be using one bit of x.
But due to structure packing arrangements (the C standard is intentionally flexible in order that compilers can optimize according to the machine architecture), it may well turn out that this still occupies as much space in memory as a regular unsigned and an array of size_1 doesn't have to be bitwise contiguous.
Generally, the smallest addressable chunk of data in C is a byte. You can not have a pointer to a bit, so you can not declare a variable of 1 bit size, But above can be one way to have 1 bit size.
Report Error
Report Error
Please Login First Click Here