我想我的運氣在這個交換功能,但我有問題。交換功能和一般功能
我希望「num1」應該換成num2的值,反之亦然。
任何人都可以把我推向正確的方向嗎?
#include <stdio.h>
void swap(int *a, int *b)
{
int temp = *a;
a = *b;
b = temp;
printf("Just checking if this badboy gets to the swapfunction.\n");
}
int main()
{
int num1 = 33;
int num2 = 45;
swap(&num1, &num2);
printf("A: %d\n", num1);
printf("B: %d\n", num2);
getchar();
return 0;
}
您應該收到來自編譯器的錯誤/警告消息,告訴您哪些線路有問題。如果不是,那麼你需要查看你的編譯器使用的設置。 –
嗨,謝謝,它在我以正確的方式使用*時起作用。 不,它並沒有提醒我,它只是按原始順序打印出原始數字。我在哪裏可以管理這樣的設置? – niyz
取決於你正在使用的編譯器和IDE ... –