1.

What are unions in C programming? Write down their syntax and an example of the same.

Answer»

A UNION is a special data type in C that lets you STORE many data types in the same memory space. Although a union can have many members, only one of them has worth at any given time. Unions are a good way to reuse the same memory space for several tasks.

The syntax of unions in C programming is given below:

union nameOfUnion { data member definition; data member definition; ... data member definition; };

An example of unions in C programming is given below:

union BOOK{char nameOfBook[15]; char nameOfBookAuthor[15]; int priceOfBook;};


Discussion

No Comment Found