0% found this document useful (0 votes)
138 views7 pages

Bit Fields

A bit field allows programmers to allocate memory to structures and unions in bits to efficiently use computer memory. It defines variables of a specified data type and size within a bit. An example shows a structure defining hours, minutes and seconds as unsigned ints of 5, 6, and 6 bits respectively. Enumeration defines user data types to assign names to integral constants for readability, such as defining days of the week.

Uploaded by

KABILA R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views7 pages

Bit Fields

A bit field allows programmers to allocate memory to structures and unions in bits to efficiently use computer memory. It defines variables of a specified data type and size within a bit. An example shows a structure defining hours, minutes and seconds as unsigned ints of 5, 6, and 6 bits respectively. Enumeration defines user data types to assign names to integral constants for readability, such as defining days of the week.

Uploaded by

KABILA R
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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