Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • C Programming Unions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 59
    Comment on it

    Union is a derived type as structures are. Union can be declared in the same manner as structures just the keyword used in defining union in union where keyword used in defining structure was struct.

     

    union car{
      char name[50];
      int price;
    };

     

     

    Union variables can be created in similar manner as structure variable.

     

    union car{
      char name[50];
      int price;
    }c1, c2, *c3;
    
    OR;
    
    union car{
      char name[50];
      int price;
    };
    -------Inside Function-----------
    union car c1, c2, *c3;

     

     

    #include <stdio.h>
    union job {         //defining a union
       char name[32];
       float salary;
       int worker_no;
    }u;
    struct job1 {
       char name[32];
       float salary;
       int worker_no;
    }s;
    int main(){
       printf("size of union = %d",sizeof(u));
       printf("\nsize of structure = %d", sizeof(s));
       return 0;
    }

     

    Memory allocation of union variable in C programming

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: