加不加int有什么區別
#include <stdio.h>
int x = 77;
void fn1()
{
? ? printf("fn1(): x=%d\n", x); ? ? ??
}
int main()
{
? ? int x = 10;
? ? if(x>0)
? ? {
? ? ? ? int x = 100;
? ? ? ? x /= 2;
? ? ? ? printf("if語句內, x=%d\n", x); ? ? ??
? ? }
? ? printf("main方法內, x=%d\n", x);
? ? fn1();
? ? return 0;
}
代碼中int x=100與x=100有什么區別?
2016-10-16
沒區別哦,你那個x已經定義了是int整數形,后面就不用再用int了,行為x是同一個
2016-10-21
int x使它成為if內的局部變量,不加的話x默認是main里定義的全局變量