Use of typedef in Union

We will use typedef with the union, in the same way we use with structure.

Just we have to replace the keyword ‘struct’ with the keyword ‘union’.

Table of Contents




typedef union student


char name[20];

int age;


int main()


printf("Details of the student are as below:\n");

st s1, s2;



printf("First student\n");

printf("Name: %s\n",;

printf("Age: %d\n",s1.age);



printf("Second student\n");

printf("Name: %s\n",;

printf("Age: %d\n",s2.age);

return 0;




The code works fine without any error, but the output doesn’t seem to be the desired one because of some limitation union.

The aim of writing the above code is just to make you understand that we can use the typedef keyword in the union too.



  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.