加不加int有什么區(qū)別
#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語句內(nèi), x=%d\n", x); ? ? ??
? ? }
? ? printf("main方法內(nèi), x=%d\n", x);
? ? fn1();
? ? return 0;
}
代碼中int x=100與x=100有什么區(qū)別?
2016-10-16
沒區(qū)別哦,你那個(gè)x已經(jīng)定義了是int整數(shù)形,后面就不用再用int了,行為x是同一個(gè)
2016-10-21
int x使它成為if內(nèi)的局部變量,不加的話x默認(rèn)是main里定義的全局變量