0
錯誤表示預期的主要表達式在int之前,在我稱爲foo的main行中。我不明白,以及如何解決它。我究竟做錯了什麼?試圖通過x,y,z作爲參數
#include <stdio.h>
#include <stdlib.h>
int foo(int *a, int *b, int c) {
/* Set a to double its original value */
*a = *a * *a;
/* Set b to half its original value */
*b = *b/2;
/* Assign a+b to c */
c = *a + *b;
/* Return c */
return c;
}
int main() {
/* Declare three integers x, y, z and initialize them to 5, 6, 7 respectively */
int x = 5, y = 6, z = 7;
/* Print the values of x, y, z */
printf("X value: %d\t\n", x);
printf("Y value: %d\t\n", y);
printf("Z value: %d\t\n", z);
/* Call foo() appropriately, passing x, y, z as parameters */
foo(int *x, int *y, int z);
/* Print the value returned by foo */
printf("Value returned by foo: %d\t\n", foo(x, y, z));
/* Print the values of x, y, z again */
printf("X value: %d\t\n", x);
printf("Y value: %d\t\n", y);
printf("Z value: %d\t\n", z);
/* Is the return value different than the value of z? Why? */
return 0;
}
將其重新標記爲'C++',因爲這不是'C#'問題。 – Corey 2013-04-07 23:19:08
除了下面的答案,z在你的代碼中永遠不會被foo讀取,它有點令人困惑。 – chrisw 2013-04-07 23:23:56