//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)
{
//在堆中申請(qǐng)100個(gè)char類型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內(nèi)存
delete []str;
str = NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請(qǐng)100個(gè)char類型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內(nèi)存
delete []str;
str = NULL;
return 0;
}
main函數(shù)需要這么寫,第一個(gè)getMax函數(shù)里面的變量需要時(shí)第0個(gè)和第2個(gè)參數(shù)。
int main(void)
{
//定義int數(shù)組并初始化
int numArr[3] = {3, 8, 6};
//自動(dòng)調(diào)用int getMax(int a, int b)
cout << getMax(numArr[0],numArr[2]) << endl;
//自動(dòng)調(diào)用返回?cái)?shù)組中最大值的函數(shù)返回?cái)?shù)組中的最大值
cout << getMax(numArr,3) << endl;
return 0;
}
int main(void)
{
//定義int數(shù)組并初始化
int numArr[3] = {3, 8, 6};
//自動(dòng)調(diào)用int getMax(int a, int b)
cout << getMax(numArr[0],numArr[2]) << endl;
//自動(dòng)調(diào)用返回?cái)?shù)組中最大值的函數(shù)返回?cái)?shù)組中的最大值
cout << getMax(numArr,3) << endl;
return 0;
}
原本一個(gè)cout的函數(shù),直接調(diào)用花了0.050秒,加上inline后用了0.060秒 還更多了。。
2017-10-20