1#include <stdio.h>
2#include <string.h>
3
4typedef struct Books {
5 char title[50];
6 char author[50];
7 char subject[100];
8 int book_id;
9} Book;
10
11int main( ) {
12
13 Book book;
14
15 strcpy( book.title, "C Programming");
16 strcpy( book.author, "Nuha Ali");
17 strcpy( book.subject, "C Programming Tutorial");
18 book.book_id = 6495407;
19
20 printf( "Book title : %s\n", book.title);
21 printf( "Book author : %s\n", book.author);
22 printf( "Book subject : %s\n", book.subject);
23 printf( "Book book_id : %d\n", book.book_id);
24
25 return 0;
26}
1// typedef [type] [alias]
2// Example:
3typedef unsigned long int ulong;
4
5ulong someNumber = 158426;
1// Typedefs can also simplify definitions or declarations for structure pointer types. Consider this:
2
3struct Node {
4 int data;
5 struct Node *nextptr;
6};
7// Using typedef, the above code can be rewritten like this:
8
9typedef struct Node Node;
10
11struct Node {
12 int data;
13 Node *nextptr;
14};
1- Type Names The command typedef can be used to give a short name to a data
2type.
3- For example, the name long long is long, so we can define a short name
4ll
5typedef long long ll;