函數(shù)中引用數(shù)組做形參,只數(shù)組名,這是本次鞏固的得到的經(jīng)驗;其次,題目中隨意取出數(shù)組中的兩個元素,讓我想起scratch中的一個參數(shù),但是不知道C++里應該怎么寫。
//定義常量count
const int count = 3;
//? int *p = ?;
//打印count次字符串Hello C++
for(int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
const int count = 3;
//? int *p = ?;
//打印count次字符串Hello C++
for(int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
它可以改變指向,但不可以改變值 int const * p
它可以改變值,但不可以改變指向 int * const p
以小星星為分界線; const:常量 (縮小修改的風險)
它可以改變值,但不可以改變指向 int * const p
以小星星為分界線; const:常量 (縮小修改的風險)
2018-03-02
int getMax(int arr[],int count)
{
int maxNum=arr[0];
for(int i = 1; i < count; i++)
{
if(maxNum<arr[i])
{
maxNum=arr[i];
}
}
return maxNum;
}
int main(void)
{
int numArr[3] = {3, 8, 6};
cout << getMax(3, 6) << endl;
cout << getMax(numArr,3) << endl;
return 0;
}
{
int maxNum=arr[0];
for(int i = 1; i < count; i++)
{
if(maxNum<arr[i])
{
maxNum=arr[i];
}
}
return maxNum;
}
int main(void)
{
int numArr[3] = {3, 8, 6};
cout << getMax(3, 6) << endl;
cout << getMax(numArr,3) << endl;
return 0;
}