By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

Returning an argument or local variable ?

P: n/a
Which one sounds not better ?

type ya(type a1){
type a2;

//do lilt somethin' for ya

return a1; // return a2;
}

Soo sorry for newbie question because I am not a professional or
intermediate coder. Thank you in advance..
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Alex6996xelA wrote:
Which one sounds not better ?
It depends on what you want to do with the function.
I would prefer return a1, if you don`t need a temporary variable to do
some calculations

If you need a temporary variable, you can return a1 or a2, depends
what value holds the result first you want to return after the "do lilt
somethin' for ya"

regards marbac
type ya(type a1){
type a2;

//do lilt somethin' for ya

return a1; // return a2;
}

Soo sorry for newbie question because I am not a professional or
intermediate coder. Thank you in advance..

Jul 23 '05 #2

P: n/a
Alex6996xelA wrote:
Which one sounds not better ?

type ya(type a1){
type a2;

//do lilt somethin' for ya

return a1; // return a2;
}


It depends on what you want to do with the function.
I would prefer return a1, if you don`t need a temporary variable to do
some calculations

If you need a temporary variable, you can return a1 or a2, depends
what variable holds the result you want to return after the "do lilt
somethin' for ya"

regards marbac

Jul 23 '05 #3

P: n/a

"Alex6996xelA" <Al*****@netzoola.com> wrote in message
news:de**************************@posting.google.c om...
Which one sounds not better ?

type ya(type a1){
type a2;

//do lilt somethin' for ya

return a1; // return a2;
}

Soo sorry for newbie question because I am not a professional or
intermediate coder. Thank you in advance..


either return the a2 temporary or pass a1 by reference (which doesn't need a
return).

void Ya(type& a1)
{
a1 = 10;
}

a1 is an alias for the passed parameter (pass by reference)

Its equivalent to someone calling you by your name or nickname, both names
denote the same instance of person. Additionally, the relationship between
the reference and its object can't be broken in void Ya(...). The reference
is permanantly bound until the scope ends.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.