DEV Community

nikilesh202
nikilesh202

Posted on

Structures and Unions

structures:

To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than or equal to one member.
syntax:
struct [structure name]
{
member definition;
member definition;
...
member definition;
};

example:
struct Person
{
char name[50];
int citNo;
float salary;
};

Unions

To define a union, you must use the union statement in the same way as you did while defining a structure. The union statement defines a new data type with more than one member for your program.
syntax:
union [union name]
{
member definition;
member definition;
...
member definition;
};

example:
union car
{
char name[50];
int price;
};
1)Both are user-defined data types used to store data of different types as a single unit.

Top comments (0)