Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Customer Support
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

output

Know the answer? Have a better solution? Share it.
Sign Up Now for FREE!
Join the thousands of students
getting ahead in their classes.
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (94%):
Date Posted: 7/22/2008 8:50:58 PM  Status: Live
output
Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
#include <iostream>
using namespace std;
int func (double &, int);
int main ()
{
double a = 19.0;
int x = 0, y = 0;
y = func (a, x);
cout << "a = " << a << ", x = " << x ", y = " << y << endl;
return (0);
}
int func (double &first, int second)
{
int third;
first /= 2.0;
second = first;
first *= 4.0;
third = first;
cout << "Second = " << second << ", and third = " << third << endl;
return (third);
}

Answers:

Member's Avatar

Expert
Karma Points: 809
Date Posted: 7/22/2008 9:43:13 PM  Status: Live
Asker's Rating: Helpful   
Response:
Second = 9, and third = 38
a = 38, x = 0, y = 38



Hopefully its correct. rate that atleast.thanks

Suicider's Comment:
little explanation would help....



Member's Avatar

Expert
Karma Points: 811
Date Posted: 7/22/2008 11:50:49 PM  Status: Live
Asker's Rating: Lifesaver   
Response:
in function func (a, x) at line no. 8, the first parameter is passed by reference but second is passed by value. So the value of "a" will change when it will be changed in function func. But second valued is passed by value, it will remain same in main function.

so value of a will be (19.0 /2 ) * 4 = 9.5 *4  = 38
    value of x remain same, so it will be 0
    value of y will be return value of function so it will also be 38.

second is integer so it's value is 19.0 /2 = 9
third will be same as first = 38


So the output will be ...

Second = 9, and third = 38
a = 38, x = 0, y = 38

Suicider's Comment:
thanks.............




By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.