This blog is under construction

Saturday 11 January 2014

How to access union members in C

Dot operator is used to access(or assign) the data members of a union variable.  Consider the following example,

union value {
         int x;
         float y;
};

union value obj;
Here, obj is a union variable of type union value.  x and y are data members of the union value. Let us see how to assign value to or access data members of union using dot operator.

obj.x = 10;

The above statement assigns value 10 to the data member x of the union variable obj.

obj  - object name(union variable name)
x     - data member in union value
.     - dot operator


Example C program to illustrate accessing union members using dot operator

  #include <stdio.h>
  union value {
        int x;
        float y;
  }obj;

  int main() {
        obj.x = 5;
        printf("Value of x is %d\n", obj.x);
        obj.y = 19.22;
        printf("Value of y is %f\n", obj.y);
        printf("Value of x is %d\n", obj.x);
        return 0;
  }


  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Value of x is 5
  Value of y is 19.219999
  Value of x is 1100595855


The value of data member y overwrites the value of x and that is reason why we see junk value in x.  Basically, all data members in a union shares same storage place.


12 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. Amazing article written, Get to now about:- tutoring orange county

    ReplyDelete
  4. **SELLING SSN+DOB FULLZ**

    CONTACT 24/7
    Telegram > @leadsupplier
    ICQ > 752822040
    Email > leads.sellers1212@gmail.com

    >>1$ each without DL/ID number
    >>2$ each with DL
    >>5$ each for premium (also included relative info)

    Price will be reduce in Bulk order

    FORMAT OF LEADS/FULLZ/PROS

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER WITH EXPIRY DATE
    ->COMPLETE ADDRESS
    ->PHONE NUMBER, EMAIL, I.P ADDRESS
    ->EMPLOYMENT DETAILS
    ->REALTIONSHIP DETAILS
    ->MORTGAGE INFO
    ->BANK ACCOUNT DETAILS

    >All Leads are Spammed & Verified.
    >Fresh spammed data of USA Credit Bureau
    >Good credit Scores, 700 minimum scores
    >Invalid info found, will be replaced.
    >Payment mode BTC, ETH, LTC, PayPal, USDT & PERFECT MONEY

    ''OTHER GADGETS PROVIDING''

    >SSN+DOB Fullz
    >CC with CVV
    >Photo ID's
    >Dead Fullz
    >Carding Tutorials
    >Hacking Tutorials
    >SMTP Linux Root
    >DUMPS with pins track 1 and 2
    >Sock Tools
    >Server I.P's
    >HQ Emails with passwords

    Contact 24/7

    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete
  5. It's appropriate time to make some plans for the future and it's time to be happy. I've read this post and if I could I want to suggest you few interesting things or advice. Perhaps you can write next articles referring to this article. I desire to read more things about it! app kosten berlin

    ReplyDelete
  6. Stunning site! Do you have any accommodating clues for trying essayists? I’m wanting to begin my own site soon yet I’m somewhat lost on everything. Would you prompt beginning with a free stage like or go for a paid alternative? There are such write me an assignment a large number of alternatives out there that I’m totally overpowered .. Any thoughts? Welcome it!

    ReplyDelete
  7. Thanks for sharing this best stuff with us! Keep sharing! I am new in the blog writing. All types blogs and posts are not helpful for the readers. Here the author is giving good thoughts and suggestions to each and every reader through this article. Quality of the content is the main element of the blog and assignment writers uk this is the way of writing and presenting.

    ReplyDelete
  8. This is a good idea for people who actually have some questions or inquiries about this topic. I am so excited to see the discussions that will be made on this thread regarding taxes. I have to say that this kind of topic should really be discussed thoroughly to people who finds it helpful so that help with essay there won't be no confusions anymore.

    ReplyDelete
  9. Union members and non-union employees have the right to receive or inspect copies of collective bargaining agreements. Sanding Wood Floors NJ

    ReplyDelete
  10. Why choosing the best Android App Development Company in India? It helps the business to rank higher in the search engines and enables the mobility of quality and relevant traffic to your website.
    Thank You!!

    ReplyDelete