Typedef keyword in c
// typedef is a keyword which is used to give name to the existing data type
// syntax- typedef <previous_name> <alias_name>;
#include <stdio.h>
int main()
{
typedef int nt; // here i given a new name to the data type int to 'nt'
nt a; // now i can use 'nt' in place of int
// it is not neccesary to use alias name or new name i can use previous name also like u can see below
int b;
//--------------------
// using typedef with structure
typedef struct library
{
char name[20];
int pages;
char author[20];
} lib; // here i given a new name to the data type library(structure) to 'lib'
lib book1, book2; // here now i can use 'lib' instead of 'struct library'
book1.pages = 100;
printf("number of pages of the book:%d", book1.pages);
}
Comments
Post a Comment