473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Returning an argument or local variable ?

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
3 1431
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
7
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D :...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
12
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
5
by: Alfonso Morra | last post by:
Hi, What is the recomended way of returning an STL container (e.g. std::string, std::vector etc fom a function? Is it by simply returning a local variable? (I doubt it) std::string...
9
by: josh | last post by:
Hi, I'm converting (for learning purpose) )a program from Java to C++ and I've a doubt: In Java every argument (variable and reference types) is passed and returned in functions by-value so if I...
14
by: Spitfire | last post by:
Hi All, I've this weird question about pointers. I would like to know how to return the address of a local variable, safely!! Isn't that a unrecommended procedure? Doesn't it have possibilities...
5
by: eriwik | last post by:
Consider this: #include <iostream> template<int A> struct test { const int& get() { return A; } } int main()
7
by: pauldepstein | last post by:
#include <iostream> using namespace std; double & GetWeeklyHours() { double h = 46.50; double &hours = h; return hours; }...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.