× Home
Next Lec → ← Previous Lec

Typedef

It is a keyword which is used to give alternate name to existing data types.

structure of typedef

                    

                        typedef [previous_name] [alias_name]; 
                    
                

Syntax of typedef

                    

                        typedef unsigned long ul;
                        //now where ever we will use 'ul' that represents 'unsigned long'
                        ul l1,l2,l3;
                        //used to give nickname for long name of data types or viceversa
                        typedef int integer;
                        integer a = 4; 
                    
                

Where typedef is important

                    

                    #include <stdio.h>
                    #include <string.h>
                    typedef struct Student
                    {
                        int id;
                        int marks;
                        char fav_char;
                        char name[34];
                    } std; // typedef [previous name] [alias name];

                    int main()
                    {
                        // struct Student s1,s2; //This old name also works
                        std s1, s2; // this also works
                    }
                
                
                    

                    int* a,b; //this doesn't make both variable pointer type only 'a' is a pointer
                    typedef int* intptr;
                    intptr c,d; //this makes both the variable pointer type and we can store address in it.