need explanation about this syntaxe

what's the diffrence between
void verser(compte &c)....

and

void verser(compte c)...
Last edited on
what do you get then?
What do u get now ? 10 1011? maybe you need c2.verser(c2)
First one passes by reference, which will affect the original object, second one passes by value which will make a copy of the object and only act on that.

For instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void func1(int a)
{
    a++;
}

void func2(int& a)
{
    a++;
}

int main()
{
    int a = 0;
    int b = 0;

    func1(a);
    func2(b);

    cout << a << endl; // outputs 0 as the original value is not affected when passed by reference, just a copy which is destroyed after the function exits.
    cout << b << endl; // outputs 1 as func2 passes by reference, changing the original

    return 0;
}
Last edited on
Topic archived. No new replies allowed.