#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個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)
{
//在堆中申請100個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;
}
const后面是誰,誰就不能變,就這么簡單:
int const *p;* 是取p指向地址中的值的意思,值得就是 *p(p地址指向的值)不能變,p可以指向其他變量的地址;
int *const p; p是地址,不能變了,*p(p指向的值)可以變。
int const *p;* 是取p指向地址中的值的意思,值得就是 *p(p地址指向的值)不能變,p可以指向其他變量的地址;
int *const p; p是地址,不能變了,*p(p指向的值)可以變。
2017-10-05