+ 1
Can someone please explain this ?
int f1(int x,int&y){ x=99; y=99; return x,y; } int main() { int a=20,b=40; f1(a,b); cout<<a<<b<<endl; return 0; } //Out 2099
4 Answers
0
A не мог бы ты написать на русском ?
+ 3
How would I do that in C? Like this:
void f1 (int x,int *y);
int main()
{ int a=20, b=40;
f1(a, &b);
printf("%d%d", a, b);
return 0;
}
void f1 (int x, int *y)
{
x=99;
*y=99;
}
Or is there a better way?
0
"int x" is the argument of the function with the name of the variable "x" of the type integer which is assigned the value "99";
"int& y" is the argument of the function with the name of the address in which the value "99" of the variable "y" is stored.
The variable “a” replaces the variable “x” with the value “99” to “20”, and “b” replaces the address name from “y” with “b” in which the value “99” is stored.
RU:
«int x» - аргумент функции с именем переменной «x» типа integer, которому присваивается значение «99»;
«int& y» - это аргумент функции с именем адреса, в котором хранится значение «99» переменной «y».
Переменная «a» заменяет переменную «x» значением с «99» на «20», а «b» заменяет имя адреса с «y» на «b», в котором хранится значение «99».