Page 134 - 6437
P. 134
strcpy( book.author, "Nuha Ali");
strcpy( book.subject, "C Programming Tutorial");
book.book_id = 6495407;
printf( "Book title : %s\n", book.title);
printf( "Book author : %s\n", book.author);
printf( "Book subject : %s\n", book.subject);
printf( "Book book_id : %d\n", book.book_id);
return 0;
}
When the above code is compiled and executed, it produces the following result:
Book title : C Programming
Book author : Nuha Ali
Book subject : C Programming Tutorial
Book book_id : 6495407
typedef vs #define
#define is a C-directive which is also used to define the aliases for various data types
similar to typedef but with the following differences:
typedef is limited to giving symbolic names to types only, whereas
#define can be used to define alias for values as well, e.g., you can define 1 as ONE, etc.
typedef interpretation is performed by the compiler whereas #define
statements are processed by the preprocessor.
The following example shows how to use #define in a program:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int main( )
{
printf( "Value of TRUE : %d\n", TRUE);
137