Замена номеров с помощью вызова по значению
/* After executing the below program, i am not getting the desired output, as the digits are not getting swapped even after calling the function */ #include<stdio.h> int swapv(int x, int y); int main() { int a = 10, b = 20; swapv(a,b); printf("\na = %d and b = %d", a,b); return 0; } int swapv(int x, int y) { int t; t = x; x = y; y = t; printf("\n x = %d and y = %d", x,y); }
выход :-
x = 20 and y =10 a = 10 and b = 20
Может ли кто-нибудь предложить правильный метод или объяснить эту программу? Как и то, почему функция не вызывается должным образом.
Что я уже пробовал:
Я могу поменять местами значения, используя метод указателя. Но почему я не могу напрямую поменять значения?