Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,954 questions

12,356 answers

573 users

How to use typedef to declaring union in C

2 Answers

0 votes
#include <stdio.h>

typedef union Complex
{
    int n;
    float f;
    char ch;
} Complex;


int main(void)
{
    Complex com;
    
    com.n = 100;
    printf("com.n = %d\n", com.n); 
 
    com.ch = 'a';
    printf("com.ch = %c\n", com.ch);
    
    return 0;
}
    
/*
run:
 
com.n = 100
com.ch = a
  
*/

 




answered Aug 18, 2017 by avibootz
0 votes
#include <stdio.h>

typedef union
{
    int n;
    float f;
    char ch;
} Complex;


int main(void)
{
    Complex com;
    
    com.n = 50;
    printf("com.n = %d\n", com.n); 
 
    com.ch = 'z';
    printf("com.ch = %c\n", com.ch);
    
    com.f = 3.14;
    printf("com.f = %.2f\n", com.f);
    
    return 0;
}
    
/*
run:
 
com.n = 50
com.ch = z
com.f = 3.14
  
*/

 




answered Aug 18, 2017 by avibootz
...