變量a會從運行的程序上疊加,因此輸出a++的值為9,10,11,12,13,14等
#include "stdafx.h"
#include
using namespace std;
int A(){
static int a=9; //去掉static 程序將會不一樣
cout<< a++<<endl;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++){
A();
}
while(1);
return 0;
}
變量a會從運行的程序上不會疊加,因此輸出a++的值全為9
#include "stdafx.h"
#include
using namespace std;
int A(){
int a=9;
cout<< a++<<endl;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++){
A();
}
while(1);
return 0;
}
賦值代碼自行驗證