Consider this code:
int i;
i = 42;
someFunction( i );
printf( "The value of i is %d\n", i );
What value will it print?
Comment away…
Consider this code:
int i;
i = 42;
someFunction( i );
printf( "The value of i is %d\n", i );
What value will it print?
Comment away…
42, Because it is the answer to Life, the Universe, Everything. And IIRC functions operate on a copy of a passed argument and don’t change the value. If you want I to change you have to pass a pointer.
Ah, yes. That’s what I thought . . . And that is true in old C. There is apparently a way in C++ to specify that the function can modify it! I was stumped by code like that, wondering how it cold possible do anything, and when I stepped through it in the debugger the variable was indeed modified. It’s a crappy C++ thing (which I don’t know) that makes it impossible to look at something simple like that and truly know what it does! Hmph.
bummer, I was going to guess 42 as well, just trying to follow the code, not knowing anything about C or it’s variants. I thought someFunction was a made up thing.
It is. Just an arbitrary function. In C, it only would get a copy of the variable, and if it changed it inside the function, when it is done, the original value would still be there. But in C++ they can change that behavior…