luc114.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 08 Feb 2026
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Store insurance policy holder info (gender, minor/major, policy name, duration) using bit-fields.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define structure with bit-fields
struct policy_holder
{
char policy_name[50];
unsigned int duration : 7; // 0-127 years is sufficient for policy duration
unsigned int gender : 1; // 0: Male, 1: Female (1 bit)
unsigned int status : 1; // 0: Minor, 1: Major (1 bit)
};
int main()
{
struct policy_holder p;
int temp_gen, temp_stat, temp_dur;
printf("--- Enter Policy Holder Details ---\n");
printf("Policy Name: ");
scanf(" %[^\n]s", p.policy_name); // Reads string with spaces
printf("Duration (Years): ");
scanf("%d", &temp_dur);
p.duration = temp_dur;
printf("Gender (0 for Male, 1 for Female): ");
scanf("%d", &temp_gen);
p.gender = temp_gen;
printf("Status (0 for Minor, 1 for Major): ");
scanf("%d", &temp_stat);
p.status = temp_stat;
printf("\n--- Policy Information Stored ---\n");
printf("Policy: %s\n", p.policy_name);
printf("Duration: %u years\n", p.duration);
// Interpret bits for display
printf("Gender: %s\n", (p.gender == 1) ? "Female" : "Male");
printf("Status: %s\n", (p.status == 1) ? "Major" : "Minor");
printf("\nSize of structure: %zu bytes\n", sizeof(p));
// Note: Size will be policy_name size + padding + integer size containing the bits
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48