See below
Protoman said:
What does this do?
int& fn(int& arg){arg++;return arg;}
//later
int y;
fn(y)=5; <-- use of uninitialised variable y
according to the body of fn, you may get an overflow. otherwise the
statement above will initialise y with 5
Why not?
What do you use it for?
I would say if you want to change the value of a static variable inside fn
between calls to fn
example (untested)
int& fn(int arg)
{
static int persist = 2;
// so some work here
return persist;
}
int main()
{
fn(1); // persist == 2 after this call
fn(2) = 7; // persist will be 7 after this
fn(3); // persist is still 7
return 0;
}
Thanks!!!
Dan