struct and union in C

Problem Solving, UVa

 

struct and union in C

These both declare same and uses are almost same;

just the difference when use

struct then need to declare with ‘struct’ keyword

struct student

{

int roll;

float age;

};

when use union then declare as

union student

{

int roll;

float age;

};

There is also a strong difference between struct and union

struct size measure by sum of all the used datatypes in struct;

like

struct student

{

int roll;

float age;

};

for this student struct datatype size is 6 bytes i.e ( 2 + 4);

union student

{

int roll;

float age;

};

where union size measure by the largest data size like in this example

student union data types size is 4 bytes.

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...