simple variable question
Question about variables getting lost. Is it possible.
void f(int &value)
{
//value 0(missing at this point)
}
int main(void)
{
int val = 10;
if(val) f(10);
return 0;
}
Passing an integer literal to f() isn't even possible the way it is defined in your snippet. You'd have to change the signature of f() to
void f(const int& value);
Apart from that, I don't really understand your question. What variable exactly is getting 'lost'?
void f(const int& value);
Apart from that, I don't really understand your question. What variable exactly is getting 'lost'?
Forgive me if i'm wrong, but i'm working on the assumption that this is C/C++ code. The & symbol in front of value is the address of or reference to operator, which is going to say address of the integer value 10, you should be able to just use int value. so when you try to use the variable 'value' it's not really there, it's jus Also, i'm not sure what the code here is to accomplish, some context may help.
For example this segment of code:
the if statement here will always process f(10) because you've set val = 10, i imagine you're trying to do something more like
Again, forgive me if i'm wrong, a little more information would be greatly useful here though. From your code it looks like you want to pass it the value 10, not a reference to the value.
For example this segment of code:
int main(void){int val = 10;//this if statement seems entirely uselessif(val) f(10);return 0;}
the if statement here will always process f(10) because you've set val = 10, i imagine you're trying to do something more like
if (val == f(10)){ //do stuff}
Again, forgive me if i'm wrong, a little more information would be greatly useful here though. From your code it looks like you want to pass it the value 10, not a reference to the value.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement