//const
#include <iostream>
#include<stdlib.h>
using namespace std;
int main(void)
{
//定義常量count
const int count = 3;
const int *p = &count;
//打印count次字符串Hello C++
for (int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
system("pause");
return 0;
}
#include <iostream>
#include<stdlib.h>
using namespace std;
int main(void)
{
//定義常量count
const int count = 3;
const int *p = &count;
//打印count次字符串Hello C++
for (int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
system("pause");
return 0;
}
#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內存
delete []str;
str = NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內存
delete []str;
str = NULL;
return 0;
}
main函數需要這么寫,第一個getMax函數里面的變量需要時第0個和第2個參數。
int main(void)
{
//定義int數組并初始化
int numArr[3] = {3, 8, 6};
//自動調用int getMax(int a, int b)
cout << getMax(numArr[0],numArr[2]) << endl;
//自動調用返回數組中最大值的函數返回數組中的最大值
cout << getMax(numArr,3) << endl;
return 0;
}
int main(void)
{
//定義int數組并初始化
int numArr[3] = {3, 8, 6};
//自動調用int getMax(int a, int b)
cout << getMax(numArr[0],numArr[2]) << endl;
//自動調用返回數組中最大值的函數返回數組中的最大值
cout << getMax(numArr,3) << endl;
return 0;
}