Page 133 - 6437
P. 133
Typedef
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:
After this type definition, the identifier BYTE can be used as an abbreviation for the type
typedef unsigned char BYTE;
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:
You can use typedef to give a name to your user-defined data types as well. For example,
typedef unsigned char byte;
you can use typedef with structure to define a new data type and then use that data type to define
structure variables directly as follows:
#include <stdio.h>
#include <string.h>
typedef struct Books
{
char title[50]; char
author[50]; char
subject[100]; int
book_id;
} Book;
int main( )
{
Book book;
strcpy( book.title, "C Programming");
136