Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
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?
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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"
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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:

Quote:
union demo
{
int integer_num;
float float_num;
}
Structure:
Quote:
struct demo
{
int integer_num;
float float_num;
}
Reply With Quote
  #4  
Old 26-11-2009
Member
 
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:

Quote:
struct emp
{

long o;
char d;

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

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Confused about difference between structure and union"
Thread Thread Starter Forum Replies Last Post
What is the difference between binary tree sort and heap sort in data structure sRIPRIYA Software Development 3 04-01-2011 01:25 AM
Difference between Structure, Classes and Enumeration Henryosa Software Development 6 22-01-2010 11:02 AM
How to define Union? seema_thk Software Development 5 15-12-2009 02:07 PM
Problem with anonymous union in C++ JTD Software Development 1 25-10-2008 05:48 PM
Should IT form a union? absolute55 Education Career and Job Discussions 1 05-09-2008 07:49 PM


All times are GMT +5.5. The time now is 11:03 PM.