我遇到了一個有趣的輸出,我想知道計算機是如何工作的。我知道,只要你有%d的字符串,你應該有一個變量來陪伴它。當我寫了兩個%d和只有一個變量時,我預計計算機會爲%d創建相同的值,因爲它只有一個變量可供使用,但由於某種原因,%d返回了x的值和變量xCubed的值。我想知道爲什麼程序返回xCubed而沒有在字符串末尾寫入xCubed。代碼如下:在C中,有關%d如何識別字符串變量的技術說明
#include <stdio.h>
int cube(int x);
int main(void){
int x = 5;
int xCubed = cube(x);
printf("Why does this number, %d, equal this number %d?", x);
return 0;
}
int cube(int x){
return x * x * x;
}
謝謝!
UB的最大... –