-1
我想讓我的頭繞指針,我試圖編寫一個程序,它將使用指針交換兩個數字。但是,我收到了標題中所述的錯誤。這裏是我的代碼:C錯誤 - 期望的聲明說明符或'...'之前的'*'令牌
//This program swaps two numbers using pointers
#include <stdio.h>
void swap(*val1, *val2);
int main() {
int num1, num2;
int *pNum1, *pNum2;
printf("Enter number 1:\n");
scanf("%d", &num1);
printf("Enter number 2:\n");
scanf("%d", &num2);
pNum1 = &num1;
pNum2 = &num2;
printf("Numbers not swapped: %d, %d\n", *pNum1, *pNum2);
swap(pNum1, pNum2);
return 0;
}
void swap(*val1, *val2) {
int temp;
temp = val1;
val1 = val2;
val2 = temp;
printf("Numbers swapped: %d, %d\n", *val1, *val2);
return;
}
絕對不知道我是怎麼錯過的。感謝您及時的回覆! – Josh