![]() |
A union contains different types of variables as its members and all these members share a memory location. In this article, we will learn how to declare and access the struct member inside a union in C++. Structure Inside Union in CTo declare a structure inside a union we can use the below syntax: Syntax to Declare Structure Inside Union in Cunion unionName { struct structName structVar; // Struct as a member of the union }; Here, structName is the name of the structure defined somewhere before the union declaration. We can also declare the structure member directly inside the union as shown: union unionName { C Program to Declare Structure Inside UnionThe below program demonstrates how we can declare a structure inside a union in C. C
Output
Number: 42 Character: A Point: (10, 20) |
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |