C program to find the size of a union

by Nideesh C on April 13, 2011 · 3 comments

in C Programming




/* C program to find the size of a union */

#include <stdio.h>

void main()
{
union sample
{
int   m;
float n;
char  ch;
};

union sample u;

printf(“The size of union =%d\n”, sizeof(u));

/*initialization */

u.m = 25;
printf(“%d %f %c\n”, u.m, u.n,u.ch);

u.n = 0.2;
printf(“%d %f %c\n”, u.m, u.n,u.ch);

u.ch = ‘p’;
printf(“%d %f %c\n”, u.m, u.n,u.ch);
}        /*End of main() */

/*—————————————–
Output
The size of union =4
25 12163373596672.000000 
-13107 0.200000 Í
-13200 0.199999 p
——————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to illustrate the concept of unions
  2. C program to input real numbers and find the mean, variance and standard deviation
  3. C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
  4. C program to find and output all the roots of a quadratic equation, for non-zero coefficients.
  5. C program to find accept a matrix of order M x N and find the sum of the main diagonal and off diagonal elements

Leave a Comment

{ 3 trackbacks }

Previous post:

Next post: