Coupon Accepted Successfully!



Suppose your C program contains a number of TRUE/FALSE variables grouped in a structure called status, as follows:


  unsigned int widthValidated;
  unsigned int heightValidated;
} status;

This structure requires 8 bytes of memory space but in actual we are going to store either 0 or 1 in each of the variables. The C programming language offers a better way to utilize the memory space in such situation. If you are using such variables inside a structure then you can define the width of a variable which tells the C compiler that you are going to use only those number of bytes. For example, above structure can be re-written as follows:

  unsigned int widthValidated : 1;
  unsigned int heightValidated : 1;
} status;

Now, the above structure will require 4 bytes of memory space for status variable but only 2 bits will be used to store the values. If you will use upto 32 variables each one with a width of 1 bit , then also status structure will use 4 bytes, but as soon as you will have 33 variables then it will allocate next slot of the memory and it will start using 8 bytes.


The C programming language provides a keyword called typedef, which you can use to give a type a new name. Following is an example to define a term BYTE for one-byte numbers:

typedef unsigned char BYTE;

After this type definitions, the identifier BYTE can be used as an abbreviation for the type unsigned char, for example:.

BYTE  b1, b2;

By convention, uppercase letters are used for these definitions to remind the user that the type name is really a symbolic abbreviation, but you can use lowercase, as follows:

typedef unsigned char byte;

You can use typedef to give a name to user defined data type as well.

Test Your Skills Now!
Take a Quiz now
Reviewer Name