Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: C++ Question

23 Mar 2012   #1

Window 7 Ultimate x64
C++ Question

I am working on my homework and need help figuring out a tough question.

2) When you call a function, as in the area and perimeter of a past assignment, you include the values to be sent to the function (the arguments) in parentheses
and the function must have been defined with parameters of an equivalent type, that will be used to receive those values

If the function is called using variables, as in cout << area(length, width) for instance, what is passed to the parameters is a copy of the values in those variables.

This is called call-by-value. In that case, the receiving parameters in the function are initialized to the contents of the two argument variables (length and width, in our example).

Based on this, given the following function:

void f (int i )


i = 57;


assuming it is called like this:


where value is a variable of type int, defined as int value = 9; what would be the result of printing variable value after the call? Explain

My System SpecsSystem Spec
23 Mar 2012   #2

XP / Win7 x64 Pro

I don't believe this is the right section for this type of question, nor am I certain you should be getting help on forums for your homework, but I feel comfortable enough asking the following questions in helping you figure this out:

- What is actually being passed to the f() function?
- Is it the variable itself that is being passed or just the value it contains?
- If it's just the value it contains, how does the f() function impact the actual value of the variable value?

I would hope there is some sort of help system set up at your school or in your class for when you need help like this. I would suggest you look into that instead.
My System SpecsSystem Spec
23 Mar 2012   #3

Window 7 Ultimate x64

I dont think there is a section on here for programming or other random computer related topics. I am taking an online class with a professor who doesn't reply very fast to my emails, and there is a small discussion board for the class, but its pretty much tumble weeds, no help there.

#include <iostream>
using namespace std;
void f (int);
int main()
int value = 9;
cout << "Value in Main: " << value << endl;
cout << "Value in Main: " << value << endl;
return 0;
void f (int i)
i = 57;
cout << "Value in Function: " << i << endl;
Value in Main: 9
Value in Function: 57
Value in Main: 9

Answer 2) There are basically two ways to pass a value to a function pass by value and pass by reference.
When you pass by value, the compiler creates a temporary variable to hold the passed value within the scope of the function.
Any changes made to the value by the function are temporary to the scope of the function;
the changes are not seen by the scope of the caller when the function returns.
When you pass by reference, the compiler passes the memory location of the variable rather than a temporary copy.
This means that any changes made to the variable by the function are also seen in the scope of the caller when the function returns.
In this case, changes made to the parameter have no effect on the argument.
I think if you printed the value of value after the call (and not in the function itself) it would still be 9,
because the value only changes in the scope of the function. The scope of variables declared within a function
or any other inner block is only their own function or their own block and cannot be used outside of them.
My System SpecsSystem Spec

23 Mar 2012   #4

XP / Win7 x64 Pro

Right. You're only passing the value of the variable value, not the reference to it. Doing anything to that value within the function doesn't change the value variable at all.
My System SpecsSystem Spec

 C++ Question

Thread Tools

Similar help and support threads
Thread Forum
Software RAID question, and NAS box software question
The more I try and learn about backups and safe storage the more questions I have. Here's my latest. I have two identical SATA III 1 Gb hard drives, designated "D Drive" under Win 7 64 bit Pro. They are under an Intel software RAID 1 on a Gigabyte GA-Z97X-Gaming 3 motherboard. All appears...
Hardware & Devices
Thermal Paste Question..(Noobish Question)
Hey guys, I recently purchased Corsair H40 that came with pre applied thermal paste. Before I placed the H40 sink on my processor, I applied a thin layer on the on the processor with Cooler Master thermal paste. So essentially I mixed the H40 pre applied thermal paste with the Cooler Master thermal...
PC Custom Builds and Overclocking
RAM Question
I will probably be getting this motherboard Gigabyte GA-Z68A-D3H-B3 rev. 1.0 Socket 1155 ATX Motherboard Intel Z68 Express Intel Core i7 i5 i3 LGA1155 Processors, Dual DDR3 2133 SATA III SATA 6.0 Gb/s Gigabit LAN SLI CrossFireX USB3.0 HDMI DVI 7.1 Channels Audio-Best Computer Online Store Hous I...
Hardware & Devices
Answer Question, Ask Question.
First (hope you get the reference): In a world where a piano is a weapon, not a musical instrument, on what does Scott Joplin play "The Maple Leaf Rag"?
Chillout Room
Logitech 5.1 surround question and soundcard question IDT and Realtek
So my situation is unique lol i have a Dell inspiron n5010 laptop running Windows 7 ultimate 64 bit the soundcard for this is either IDT 92HD79B1, v., A01 or A03 i dont know what the default one mine came with is. Documentation i hope that helps ^ and the attatchment i...
Sound & Audio

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 07:59.
Twitter Facebook Google+