C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

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

0 votes
57 views
asked Jan 7, 2014 by smith Geek (15,340 points)

1 Answer

0 votes

 

#include<stdio.h>

#include<conio.h>

#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(“\n Type of vehicle: %d”,v.type);

printf(“\n Fuel: %d”,v.fuel);

printf(“\n Model: %d”,v.model);

getch();

}

Output:

Type of Vehicle : 4

Fuel : 2

Model : 5 

answered Jan 7, 2014 by rajesh Guru (39,140 points)

...