You are on page 1of 7

Bit Fields

A bit field is a data structure that allows the


programmer to allocate memory to structures
and unions in bits in order to utilize computer
memory in an efficient manner.
Syntax
struct
{
data_type variable_name : size_in_bits;
};
Program

#include <stdio.h>
struct time
{

unsigned int hours: 5; // Size restricted to 5 bits


unsigned int minutes:6; // Size restricted to 6 bits
unsigned int seconds:6; // Size restricted to 6 bits
};
int main()
{
struct time t = {11, 30, 10}; // Here t is an object of the structure time
printf("The time is %d : %d : %d\n", t.hours, t.minutes, t.seconds);
return 0;
}
Enumeration (or enum) in C

Enumeration (or enum) is a user defined data


type in C. It is mainly used to assign names to
integral constants, the names make a program
easy to read and maintain.
Syntax
• enum variable name{constant1, constant2,
constant3, ....... };
Program
#include<stdio.h>
enum week{Mon, Tue, Wed, Thur, Fri, Sat, Sun};
int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}
Program
#include<stdio.h>
 
enum year{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
 int main()
{
   int i;
   for (i=Jan; i<=Dec; i++)     
   printf("%d ", i);
       
   return 0;
}

You might also like