ProAnswers.org

Write a C program to store the information of vehicles. Use bit fields to store the status of information ?

#include 

#include 

#define PETROL 1 

#define DISEL 2 

#define TWO_WH 3 

#define FOUR_WH 4 

#define OLD 5 

#define NEW 6 

void main() 

{ 

struct vehicle 

{ 

unsigned type:3; 

unsigned fuel:2; 

unsigned model:3; 

}; 

struct vehicle v; 

v.type=FOUR_WH; 

v.fuel=DISEL; 

v.model=OLD; 

clrscr(); 

printf(“

Type of vehicle: %d”,v.type);

printf(“

Fuel: %d”,v.fuel);

printf(“

Model: %d”,v.model);

getch(); 

} 

Output: 

Type of Vehicle : 4 

Fuel : 2 

Model : 5