Results 1 to 4 of 4

Thread: Confused about difference between structure and union

  1. #1
    Join Date
    Nov 2009
    Posts
    652

    Confused about difference between structure and union

    Hi All,

    I am one of the beginner in the field of programming. I want your help to understand the difference between structure and union. For me the Structure and Union seems similar, I am not able to differentiate between them.

    Do you know any difference between structure and union?
    Can able to provide me the example which show the difference between structure and union?

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Confused about difference between structure and union

    Hi,

    Following are the main difference between between structure and union of C language:

    A. Every member of "structure" has it's own space of memory, While in "Union" all member use only single block of memory.

    B. Only required memory is reserved to member of the "structure", While in the "Union" max required memory is being allocated to the member of "Union"

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Confused about difference between structure and union

    You can access all structure members at single use, On other hand in Union you can access only one union member at single time. This is the only difference which is I know. Following is the example of Structure and Union:

    Union:

    union demo
    {
    int integer_num;
    float float_num;
    }
    Structure:
    struct demo
    {
    int integer_num;
    float float_num;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Confused about difference between structure and union

    Hi Friend,

    I know the concept of structure very well, But don't have sound knowledge about Union. Structure is works as user defined data types in C programming.The only difference between them is members in the structure individually use block of memory ,but Union members use only one common space.

    Refer below example:

    struct emp
    {

    long o;
    char d;

    };
    Here variable "o" is of type long and variable "d" is of type character.

Similar Threads

  1. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  2. Difference between Structure, Classes and Enumeration
    By Henryosa in forum Software Development
    Replies: 6
    Last Post: 22-01-2010, 11:02 AM
  3. How to define Union?
    By seema_thk in forum Software Development
    Replies: 5
    Last Post: 15-12-2009, 02:07 PM
  4. Problem with anonymous union in C++
    By JTD in forum Software Development
    Replies: 1
    Last Post: 25-10-2008, 05:48 PM
  5. Should IT form a union?
    By absolute55 in forum Education Career and Job Discussions
    Replies: 1
    Last Post: 05-09-2008, 07:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,138,611.68661 seconds with 17 queries