/* 变量的作用域: 在代码块中,变量score如果没有int重定义,那么赋值给了离他最近的int定义的score; printf打印的是同一层级定义的score的最后一次赋值结果. */
#include <stdio.h>
int main(int argc, const char * argv[]) {
int score = 100; printf("score=%d\n",score); { score = 200; printf("score=%d\n",score); int score = 300; score = 400; printf("score=%d\n",score); { score = 500; printf("score=%d\n",score);
} //在同一层级离他最近的int定义的score被赋值两次,最后一次是500,所以打印了500; printf("score=%d\n",score);
} printf("score=%d\n",score);
return 0; } 代码输出结果:score=100 score=200 score=400 score=500 score=500 score=200 //粘贴过来的代码没有了缩进...
|