GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 386 of 453    Print  
What is the difference between structure & union?
how can we multiply this A*B without using "*" operator?


  
Total Answers and Comments: 5 Last Update: September 10, 2008     Asked by: sathishkumar 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: rashmi.mohanty
 
Difference are:
1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.

2. In union, one block is used by all the member of the union but in case of structure, each member have their own memory space.

3. union is best in the environment where memory is less as it shares the memory allocated.But structure can not implemented in shared memory.

4. As memory is shared,ambiguity are more in union,but less in structure.

5. self referencial union can not be implemented in any datastructure ,but self referencial structure can be implemented.

Above answer was rated as good by the following members:
pankajzalera14
October 24, 2007 09:23:00   #1  
Sree Bhaarath        

RE: What is the difference between structure & union?
A structure is a union in which each defined data type will have its own memory.Ex
Struct{
int a;
float b;
} In the above structure b has highest memory but bith a b are having personalised memory Where as in union the highest memory data type will be memory for entire union.Suppose if a float element is intialaised and an int element the int will be first located on 2 bytes and then the next 2 bytes will be the float.

 
Is this answer useful? Yes | No
June 09, 2008 07:36:06   #2  
jintojos Member Since: May 2008   Contribution: 29    

RE: What is the difference between structure & union?

The difference between structure and union is that......
if we declared two structure variables as
struct strct1 x y;
then the two structure variables x and have different memory location.
But we declared tow unio variables as
union uni1 x y;
then the two unio variables x and have same memory location.
that is the main difference between an structure and union


 
Is this answer useful? Yes | No
August 22, 2008 02:38:04   #3  
laxmii.s Member Since: August 2008   Contribution: 3    

RE: What is the difference between structure & union?
Size of the structure is sum of the size of each member in the structure. But size of the union is size of largest member in the union because the union members are overlaps on each other in memory.

bye

 
Is this answer useful? Yes | No
September 10, 2008 11:22:11   #4  
rashmi.mohanty Member Since: September 2008   Contribution: 8    

RE: What is the difference between structure & union?
Difference are:
1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.

2. In union one block is used by all the member of the union but in case of structure each member have their own memory space.

3. union is best in the environment where memory is less as it shares the memory allocated.But structure can not implemented in shared memory.

4. As memory is shared ambiguity are more in union but less in structure.

5. self referencial union can not be implemented in any datastructure but self referencial structure can be implemented.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 10, 2008 11:25:21   #5  
rashmi.mohanty Member Since: September 2008   Contribution: 8    

RE: how can we multiply this A*B without using "*" operator?
void main()
{
int n1 3 n2 4;
int i mul 0;
for(i 1;i< n2;i++)
mul mul+n1;
printf("MULTIPLICATION VALUE: d" mul);
}


I think this is the best way to represent the program

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape