蔭試圖編譯這個程序,但我得到警告,當我運行VC++ 2010調試器彈出:( 這裏是我的代碼:警告:未初始化的變量//但我已初始化! C++編譯器錯誤?
#include <iostream>
using namespace std;
int num;
int min(int mas[])
{
int i,minn,index; /* But I have declared them : ((((*/
for(i=0;i<num;i++)
{
if(mas[i]!=0)minn=mas[i];
break;
}
if(i==num) return 0;
for(i=0;i<num;i++)
if(mas[i]!=0 && minn>mas[i])
{
minn=mas[i];
index=i;
}
mas[index]=0;
return minn;
}
int main()
{
cin>>num;
int *array=new int[num]; int tmp;
tmp=min(array);
}
,這裏是一個編譯器日誌:
prog.cpp: In function ‘int min(int*)’:
prog.cpp:6: warning: ‘index’ may be used uninitialized in this function
prog.cpp:6: warning: ‘minn’ may be used uninitialized in this function
我做錯了嗎?或者它是編譯器錯誤?:) 謝謝:)
您需要改進您的代碼。函數int min(int mas [])'太難看了。 – Stan