Interview Questions and Answers :: Cisco
Home > Experience Archives > Cisco > Interview Question Set 6 > Discussion
6. Is it possible to print sizeof bit field operator and why?
Answer:
#include <stdio.h>
#pragma pack(2)
// if above line of code will be there then memory alignment boundry will be set to 2 so size of below will come as 2, else 4 byte.
int main()
{
typedef struct
{
unsigned int x:1
} x;
printf("size of bitfield struct %d ",sizeof(x));
return 0;
}
Hari
10 Feb, 2019 8:10 PM
#include <stdio.h>
#pragma pack(2)
// if above line of code will be there then memory alignment boundry will be set to 2 so size of below will come as 2, else 4 byte.
int main()
{
typedef struct
{
unsigned int x:1
} x;
printf("size of bitfield struct %d ",sizeof(x));
return 0;
}
Report Error
Report Error
Please Login First Click Here