Loading
submit to reddit
May 22, 2013, 08:32:34 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Passing multiple arguments for function to take in  (Read 318 times)
MKANET
Newbie
*
Posts: 6


« on: June 22, 2012, 10:28:14 PM »

I have played this part of "Lesson 18: Arguments and Return Values" video more times that I'm willing to admit.  However, I just can't figure out what happens to each argument taken in by the function and why.

The way I see this (which is completely wrong):

No matter what value is sent to the function's local variable iInt2, the value will always change to 1.
Also, no matter what value is sent to the function's local variable iInt3, the value will always change to 0.
The only instance where the function's local variable doesn't override the value sent to it is iInt1.

Hence:

The value 4 processed by function Sum, will = 5    (because 4 + 1 + 0 = 5)
The values 4, 3 processed by function Sum, will be = 5 (because 4 +1 + 0 =5)
The values 4, 3, -6 processed by function Sum, will be = 5 (because 4 +1 + 0 =5)

5
5
5

So... what does really happen?  I'm trying to comprehend this in a way that makes more sense that the above.

Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 901



« Reply #1 on: June 22, 2012, 11:03:39 PM »

When 4 is passed in, the default values are used for the last two parameters: 4+1+0=5. When 4 and 3 are passed in the 3 is used instead of the default value of 1 for iInt2. So, you get 4+3+0=7. When 4, 3, and -6 are passed in, none of the default values are passed in. So, iInt1 = 4, iInt2 = 3 and iInt3 = -6 and you get 4+3+(-6)=1.

I hope that clears it up. If you still have questions, please ask.  Wink

Mike
Logged
MKANET
Newbie
*
Posts: 6


« Reply #2 on: June 23, 2012, 12:34:10 PM »

It completely clears it up.  I didn't realize that the local variables declared in the function will only use the predefined default mathematical operators if no value is passed for that argument.  That's definitely good to know.

BTW As I'm getting used to using new C++ terminology, please feel free to correct my sentences even if I still manage to get the point across.

Thanks!
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!