C++??new??delete??????
???????????? ???????[ 2015/10/13 10:37:50 ] ????????.NET ???????????
???????new char??delete????
????1. ???????
????#include <iostream>
????using namespace std;
????void main()
????{
????char* des = new char();
????des = "testing!";
????cout<<des<<endl;
????delete des; //???delete?????
????}
????2. ????
?????????е?delete???????????
????3. ???
????v1
????????new?????????char???????????????????des??????????
????????????"testing!"??????????????????????des??????
???????????????new????????????????????????????????????????????????????????????????????????????????????????????????????й?
????delete??????????????????delete???????new?????????????????????????????????????????
????v2
????1.
????char* des = new char();
???????????????byte???????????des = "testing!";???¥????????????"testing!"????des????????????????????????????????????????????????y?"testing"??????????des??????des????????des = "testing!"?е?des????????char* des = new char();?????????
????4. ???????
????V1
????#include <iostream>
????using namespace std;
????void main()
????{
????char* des = new char[10];
????memset(des?? 0?? 10);
????strcpy(des?? "testing!");
????cout << des << endl;
????delete des;
????}
????V2 ????
????#include <iostream>
????using namespace std;
????void main()
????{
????char* des = new char[10];
????memset(des?? 0?? 10);
????strcpy(des?? "testing!");
????cout << des << endl;
????delete[] des; // new[]??delete[]???????????char??????????????????6¥????д??????????????
????}
????????new int??delete
????1. ????
#include <iostream>
using namespace std;
void main()
{
//?????????
int *a = new int [2];
for (int i=0;i<2;i++)
{
a[i] = 1;
}
for (int i=0;i<2;i++)
{
printf("%d
"??a[i]);
}
delete[] a;
//??????????
int **b = new int *[2];
for (int i=0;i<2;i++)
{
b[i] = new int [2];
}
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
b[i][j] = 2;
}
}
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
printf("%d "??b[i][j]);
}
printf("
");
}
for (int i=0;i<2;i++)
{
delete[] b[i];
}
delete[] b;
system("pause");
}
????2. ????????????
??????char?????????????????????????????????????????????????????????????????????????????
????????С??
??????new???????У??漰??????????????С???
??????????????
????new??delete??????????????й???????????????????"[]"????“()”?????£?
????char * szData=new char(100); (????)
????char *szData=new char[100];???????
????int**a = new int*[2];
????for(int i=0;i<2;i++){
????*(a+i) = new int[3]; //a[i] = new int[3];
????for(int j=0;j<3;j++){
????*(*(a+i)+j) = j; //a[i][j] = j;
????}
????}
????for(int i=0;i<2;i++){
????for(int j=0;j<3;j++){
????cout<<"a["<<i<<"]["<<j<<"]="<<*(*(a+i)+j)<<endl;
????}
????cout<<endl;
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11