+ 6
If we do as below ,will value of t calculated in function goes to address of t?
function definition: int func(int X,int y,int z,int &t) {t=(X+y+z)/2;}
2 Respostas
+ 3
Actual argument corresponding to t is gets changed as t value, in c++.
Pls Tag language also
In c, you need to use pointer instead of variable to store address. [&t => *t]
+ 3
You dod not specify a relevant language in thread tags, so
In C you would probably use pointer to pass address of variable <t>.
int func(int X, int y, int z, int* t)
{
*t = (X + y + z) / 2;
// no return value ???
}
In C++ you have the option to use reference.
int func(int X, int y, int z, int& t)
{
t = (X + y + z) / 2;
// no return value ???
}
I think the way <t> is defined in your example isn't quite right if you meant C language, it is fine in C++. And since the function doesn't return anything, you might want to change its return type to `void`. You are returning the result out through the <t> parameter after all.