GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Concepts  >  Data Structures
Go To First  |  Previous Question  |  Next Question 
 Data Structures  |  Question 177 of 198    Print  
What would be the output of the following progam?


union check
{
char name[10];
int age;
}A;
void main()
{
printf("Enter your name: ");
scanf("%s",&A.name);
printf("Enter your age: ");
scanf("%d",&A.age);
printf("Name=%s Age=%d",A.name,A.age);
}

  
Total Answers and Comments: 3 Last Update: August 22, 2008     Asked by: jitudash 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
September 21, 2007 07:08:33   #1  
kalaivanan        

RE: What would be the output of the following progam?
ans would be the name &string
 
Is this answer useful? Yes | No
February 19, 2008 04:12:23   #2  
contact.nidhigupta Member Since: January 2008   Contribution: 3    

RE: What would be the output of the following progam?union check{ char name[10]; int age;}A;void main(){ printf("Enter your name: "); scanf("%s",&A.name);printf("Enter your age: "); scanf("%d",&A.age);printf("Name=%s Age=%d",A.name,A.age);}
Since it is a union so both age and name will share same storage area. output will actually depend which data member was modified last. So in this case, since age is the last to be modified (entered), so name will come as character value of age.
 
Is this answer useful? Yes | No
August 21, 2008 08:43:34   #3  
appu502 Member Since: August 2008   Contribution: 1    

RE: What would be the output of the following progam?union check{ char name[10]; int age;}A;void main(){ printf("Enter your name: "); scanf("%s",&A.name);printf("Enter your age: "); scanf("%d",&A.age);printf("Name=%s Age=%d",A.name,A.age);}
Output:
enter your name:Appu
Name=Appu

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape