#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy_s(str,100,"Hello imooc");
//打印字符串
cout << str << endl;
system("pause");
//釋放內存
delete[]str;
str = NULL;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內存中
strcpy_s(str,100,"Hello imooc");
//打印字符串
cout << str << endl;
system("pause");
//釋放內存
delete[]str;
str = NULL;
return 0;
}
說一個比較好記的方法來區分 int const *p與 int* const p,把*讀作pointer to然后從后往前讀.
第一個int const *p就可以讀作 p is a pointer to const int,p是指向常量的指針
第二個int* const p就可以讀作 p is a const pointer to int,p是指向int型的常指針
第一個int const *p就可以讀作 p is a pointer to const int,p是指向常量的指針
第二個int* const p就可以讀作 p is a const pointer to int,p是指向int型的常指針
2018-05-28