Re: The use of CONST and '&' as argument parameter



// call by value
void function1 (int para1)
{
para1 = 2; // modifies local copy of para1 (and not the variable
passed as para1)
}

// call by reference
void function2 (int& para1)
{
para1 = 2; // modifies the variable referenced by para1 ie x
}

void function3 (const int para1)
{
para1 = 2; // illegal - can't modify a const parameter
}

int x = 100;
function1 (x); // x still equals 100

function2 (x); // x = 2

------------------


--
Best regards
Mark

"Jack" <jl@xxxxxxxxxx> wrote in message
news:e4lgSt06FHA.1276@xxxxxxxxxxxxxxxxxxxxxxx
> In the case, which is better use
> void function1 (CONST int para1);
> or
> void function1 (int& para1);
> are they equvilent? (can't spell sorry)
> Thanks
> Jack
>


.



Relevant Pages

  • Re: std::string, Append a number
    ... Specific reference here: http://www.boost.org/libs/conversion/lexical_cast.htm ... int main ... Regards, ... Matt Hurd ...
    (comp.lang.cpp)
  • Re: Framework 2.0 still used after 3.0 install
    ... I'm sorry it seems like there are some issue with MSDN website now. ... I agree with Mark. ... Please add a reference to WindowsBase.dll, ... Best regards, ...
    (microsoft.public.dotnet.framework)
  • Re: Problem of Pass by Reference in C++
    ... > Best regards, ... reference to an int ...
    (comp.lang.cpp)
  • Re: Resizing Panel Problem
    ... Mark Arteaga, MVP ... >>> private void frmViewSchedule_Load ... >>> private int intX; ... >>> private string strFullDetails; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: [PATCH] mm: use-once cleanup
    ... The idea is to mark a page PG_useonce on pagecache entry and modify the ... It wouldn't hurt to write what problem useonce fixes directly into the source ... fault time or when scanning the lists for reclaim in shrink_page_list. ... make the reference bit for all active pages have the same lifetime. ...
    (Linux-Kernel)