//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;
}