Shop Management using Structure and Union in C


A union is a user-defined type similar to structs in C except for one key difference.

Structures allocate enough space to store all their members, whereas unions can only hold one member value at a time.

Source Code

//Shop Management using Structure and Union
#include<stdio.h>
 
//Book -> Name,Author,price
//Cell-> Model,Price,color
struct store
{
    double price;  //8
    char *name;    //4
    char *author;  //4
    char *model;   //4
    char *color;   //4
 
}o;
 
	struct store2
	{
		double price;  //8
		union{
			struct{
				char *name;    //4
				char *author;  //4
			} book;
			 struct{
				char *model;    //4
				char *color;    //4
			} cell;
		}product;
 
	}o2;
 
int main()
{
    o.model="Nokia";
    o.color="Red";
    o.price=3550.00;
    printf("\nSize : %d",sizeof(struct store)); //24
    printf("\nSize : %d",sizeof(struct store2)); //16
    o2.product.cell.model="Nokia";
    o2.product.cell.color="Red";
    o2.price=3550.00;
    return 0;
}
 
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes