for (int i = 0; i < 10; i++)
{
static int number = 1;
cout << number << endl;
number++;
}
for (int i = 0; i < 10; i++)
{
int number = 1;
cout << number << endl;
number++;
}
int* p = (int*)malloc(sizeof(int)*10);
p[0] = 9;
p[1] = 4;
cout << p[1] << endl;
free(p);
int* p1 = (int*)calloc(sizeof(int),10);
for (int i = 0; i < 10; i++)
p1[i] = i;
for (int i = 0; i < 10; i++)
cout << p1[i] << endl;
int* p2 = new int;
*p2 = 7;
cout << *p2 << endl;
delete p2;
?
int* p3 = new int[10];
for (int i = 0; i < 10; i++)
p3[i] = i;
for (int i = 0; i < 10; i++)
cout << p3[i] << endl;
delete p3;
int** pp = new int*[10];
for (int i = 0; i < 10; i++)
pp[i] = new int[10];
?
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
pp[i][j] = i * 10 + j;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
cout << pp[i][j] << "\t";
cout << endl;
}
1 指针要有指向 没有指向的置空
2 申请的内存要释放
3 释放的内存要置空
……
原文:https://www.cnblogs.com/ZhenXin0101/p/13524875.html