ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
What is the main difference between STRUCTURE and UNION?
 Question Submitted By :: Mariaalex007
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 1
All the members of the structure can be accessed at
once,where as in an union only one member can be used at a time.
Another important difference is in the size allocated to a
structure and an union.
for eg:
struct example
{
  int integer;
  float floating_numbers;
}
the size allocated here is sizeof(int)+sizeof(float);
where as in an union
union example
{
  int integer;
  float floating_numbers;
}
size allocated is the size of the highest member.
so size is=sizeof(float);
 
Is This Answer Correct ?    47 Yes 3 No
Vijay Nag
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 2
1) Structure: The size in bytes is the sum total of size of 
all the elements in the structure, plus padding bytes.
2) Size of in bytes of the union is size of the largest 
variable element in the union. 

i.e In case of Union, the elements making up the 
union 'overlap' in memory OR they are accessed as diffrent 
name/type at diffrent places in the program.

Whereas in case of Struct, each of the elements have a 
distinct identity.
 
Is This Answer Correct ?    22 Yes 2 No
Ravi
 
 
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 3
The difference between structure and union in c 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
 
Is This Answer Correct ?    17 Yes 0 No
Dinesh Haridoss
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 4
At the one time only one data member can be access...or can 
be used.
 
Is This Answer Correct ?    7 Yes 7 No
Anurag
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 5
All the members of the structure can be accessed at
once,where as in an union only one member can be used at a 
time.
 
Is This Answer Correct ?    8 Yes 0 No
Om Prakash Mit
 
  Re: What is the main difference between STRUCTURE and UNION?
Answer
# 6
. 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
1.	Let’s say a structure containing an int, char and 
float is created and a union containing int char float are 
declared. struct TT{ int a; float b; char c; } Union UU{ 
int a; float b; char c; } 
2.	sizeof TT(struct) would be >9 bytes (compiler 
dependent-if int,float, char are taken as 4,4,1) 
3.	sizeof UU(Union) would be 4 bytes as supposed from 
above.If a variable in double exists in union then the size 
of union and struct would be 8 bytes and cumulative size of 
all variables in struct
 
Is This Answer Correct ?    3 Yes 0 No
Priti
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }  1
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }  1
plz send me all data structure related programs  1
main() { extern int i; i=20; printf("%d",i); }  1
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4 HCL1
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }  1
How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw... Oracle3
main() { char a[4]="HELL"; printf("%s",a); } Wipro1
int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }  1
#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }  1
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?  1
#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }  1
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }  1
void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above HCL1
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }  1
Finding a number multiplication of 8 with out using arithmetic operator NetApp8
How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”) HCL1
main() { char *p; p="Hello"; printf("%c\n",*&*p); }  1
main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }  1
main() { printf("%d", out); } int out=100;  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com