Computer Science, asked by ashokkumarsingh3932, 9 months ago

Difference between structure and union in c programming with example

Answers

Answered by shuklavaibhav9212019
0

Answer:

The structure and union both are the container data types that can hold data of any “type”. The one major difference that distinguishes structure and union is that the structure has a separate memory location for each of its members whereas, the members of a union share the same memory location

example-:#include <stdio.h>

union unionJob

{

  //defining a union

  char name[32];

  float salary;

  int workerNo;

} uJob;

struct structJob

{

  char name[32];

  float salary;

  int workerNo;

} sJob;

int main()

{

  printf("size of union = %d bytes", sizeof(uJob));

  printf("\nsize of structure = %d bytes", sizeof(sJob));

  return 0;

}

Similar questions