小编Nur*_*san的帖子

为什么全局变量会翻倍两次?

#include <stdio.h>
#define abs(x) (x < 0 ? -x : x)
int x;
int doubleGlobalX()
{
    x*=2;
    return x;
}

int main()
{
    scanf("%d",&x);//5
    printf("%d\n",abs(doubleGlobalX()));//20
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当输入5为时,此代码的输出为20。当输入为时15,输出为60。不知道为什么它将两倍于全局。

c macros c-preprocessor

1
推荐指数
1
解决办法
43
查看次数

标签 统计

c ×1

c-preprocessor ×1

macros ×1