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

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


Distribute your Resume to 500+ Job Boards & Recruiters


7,765 questions

10,845 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
...