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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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 ?    42 Yes 2 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 ?    20 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 ?    14 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 ?    6 Yes 3 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 ?    4 Yes 0 No
Om Prakash Mit
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }  1
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }  1
Find your day from your DOB? Microsoft12
how to delete an element in an array  1
main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above HCL1
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }  1
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }  1
void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(“%d”,k); }  1
why java is platform independent? Wipro10
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) Disney3
struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error HCL1
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above HCL1
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }  1
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }  1
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }  1
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.  1
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }  1
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10 HCL1
How to reverse a String without using C functions ? Wipro13
 
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