Skip to main content

Command Palette

Search for a command to run...

Array of Unions

Published
•1 min read•View as Markdown

Program:

#include <stdio.h>
#include <string.h>

union id_proof
{
 char pan_id[11];
 char voter_id[11];
 long long int aadhaar_num;
 char passport_num[9];
};

int main()
{
 union id_proof customers[4];

 // assigning values to various members of the customers array of union variables
 strcpy(customers[0].pan_id, "AEPNL1217G");
 strcpy(customers[1].voter_id, "awc1224523");
 customers[2].aadhaar_num = 123456789123;
 strcpy(customers[3].passport_num, "K1234567");
 // printing the values of the members of the customers array of union variables

 printf(" Pan Number of first customer : %s \n", customers[0].pan_id);
 printf(" Voter Number of second customer : %s \n", customers[1].voter_id);
 printf(" Aadhaar Number of third customer : %lld \n", customers[2].aadhaar_num);
 printf(" Passport Number of fourth customer : %s \n", customers[3].passport_num);

 return 0;
}

Output:

9 views

More from this blog

P

Programming Tutorials

89 posts