标签:asp let nbsp 数组 inter cpp strong class malloc
1 1 //变量申请 2 2 Type*pointer = new Type; 3 3 //.... 4 4 delete pointer; 5 5 6 6 //数组申请 7 7 Type*pointer = new Type[N]; 8 8 //.... 9 9 delete[] pointer;
10 #include "stdio.h" 11 int main() 12 { 13 //new可以初始化 14 int *p = new int(100); 15 //*p = 5; 16 *p = *p + 5; 17 printf("p=%p\n",p); 18 printf("*p=%d\n",*p); 19 delete p; 20 p = new int[10]; 21 for (int i = 0; i < 10;i++) 22 { 23 p[i] = i + 1; 24 printf("p[%d]=%d\n",i,p[i]); 25 } 26 delete p; 27 return 0; 28 }
运行结果:
pi@raspberrypi:~ $ g++ main.cpp
pi@raspberrypi:~ $ ./a.out
p=0x15c4058
*p=105
p[0]=1
p[1]=2
p[2]=3
p[3]=4
p[4]=5
p[5]=6
p[6]=7
p[7]=8
p[8]=9
p[9]=10
标签:asp let nbsp 数组 inter cpp strong class malloc
原文地址:https://www.cnblogs.com/chengeputongren/p/12177879.html