У меня есть быстрый вопрос. я пытаюсь сделать программу сложения векторов с некоторыми функциями, но когда я запускаю это быстро, чтобы проверить число на выходе еще 0.Передача структурных переменных между функциями
void input(struct vectors v1, struct vectors v2);
void addition (struct vectors v1, struct vectors v2);
struct vectors {
int x;
int y;
}v1, v2;
int main(int argc, const char * argv[]) {
input(v1, v2);
addition(v1, v2);
}
void input(struct vectors v1,struct vectors v2){
cout << "Input x and y componenets of vector 1" << endl;
cin >> v1.x;
cin >> v1.y;
cout << "Input x and y componenets of vector 2" << endl;
cin >> v2.x;
cin >> v2.y;
}
void addition (vectors v1, vectors v2){
int xsum = v1.x +v2.x;
int ysum = v1.y +v2.y;
cout << "sum of the x variables is " << xsum << endl << "sum of the y variables is " << ysum <<endl;
}
C++ является передача по значению. Вы написали свой код, как если бы он проходил по ссылке. – juanchopanza