This blog is under construction

Saturday 11 January 2014

Declaration of a union variable in C

Union variable can be declared while defining a union or after defining a union.

Let us see how to declare a union variable while defining a union.
union book {
          char name[32];
          int price;
}obj;

Here, obj is a union variable of type union book and it is declared while defining the union book.

Let us see how to declare a union variable after defining a union.
union book {
          char name[32];
          int price;
};

union book obj1, obj2;

Here, obj1 and obj2 are union variables of type union book.  And they are declared after defining the union book.

Union variable declaration example in C

  #include <stdio.h>
  #include <string.h>
  union book {
        char name[32];
        int price;
  }obj1;  // union variable declaration at definition

  union book obj2;  // union variable declaration after definition

  int main() {
        strcpy(obj1.name, "Davinci code");
        printf("obj1.name: %s\n", obj1.name);
        strcpy(obj2.name, "Twilight");
        printf("obj2.name: %s\n", obj2.name);
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  obj1.name: Davinci code
  obj2.name: Twilight




6 comments:

  1. Nice article admin thanks for share your atricle keep share your knowledge i am waiting for your new post check mens winter jackets polo shirts kindly review and reply me

    ReplyDelete
  2. Hello Everyone !

    USA SSN Leads/Dead Fullz available, along with Driving License/ID Number with good connectivity.

    All SSN's are Tested & Verified.

    **DETAILS IN LEADS/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL
    ->EMPLOYEE DETAILS

    *Price for SSN lead $2
    *You can ask for sample before any deal
    *If you buy in bulk, will give you discount
    *Sampling is just for serious buyers

    ->Hope for the long term business
    ->You can buy for your specific states too

    **Contact 24/7**

    Whatsapp > +923172721122

    Email > leads.sellers1212@gmail.com

    Telegram > @leadsupplier

    ICQ > 752822040

    ReplyDelete
  3. If you care about some famous celebrities click https://www.celebswikipost.com

    ReplyDelete
  4. I suppose if I had to pick a perfect article, it would be yours. I know no article is perfect, but yours is as close as it gets. Good job. But Mobile app development in Dubai leverages cutting-edge technology to create user-centric applications, meeting the demands of this dynamic and tech-savvy business environment.

    ReplyDelete
  5. Moreover, the UAE's strategic location and business-friendly environment make it an attractive destination for companies looking to outsource their Website designers UAE projects. With its advanced infrastructure, robust regulatory framework, and access to global markets, the UAE offers a conducive ecosystem for businesses to thrive and expand their operations. Website development companies in the UAE leverage this advantage to deliver high-quality services to clients around the world, ensuring seamless communication, timely delivery, and cost-effective solutions.

    ReplyDelete