我也是這樣寫的,但是編譯的時候有錯誤,說啥strcpy這個沒有申明,不懂啊?。?!
#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 <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;
}
// 說一下指針變量的( * )星號什么加,什么時候不加
int x = 10;
int *p = &x;
cout << p << endl; // 使用指針變量p存儲的地址, 不加( * )星號
cout << *p << endl; // 使用指針訪問值, 加( * )星號
int x = 10;
int *p = &x;
cout << p << endl; // 使用指針變量p存儲的地址, 不加( * )星號
cout << *p << endl; // 使用指針訪問值, 加( * )星號
2018-04-22
難怪其它高級語言都有垃圾回收機制,自己管理增加代碼量不說,還容易忘記。果然越是底層,手動能力要求就越高,不過我要征服它,我的夢想是成為高手而不僅僅是碼農(nóng)
2018-04-21
#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;
}