#include<iostream>usingnamespace std;constint maxn =1000;int num;//数组的初始长度为0int ary[maxn];boolmydelete(int x){if(x <0|| x >= num){returnfalse;}for(int i = x +1; i < num; i++){
ary[i -1]= ary[i];}
num--;returntrue;}voidshow(){for(int i =0; i < num; i++){printf("%d %s", ary[i],(i==num-1)?"\n":" ");}}intmain(void){
num =6;for(int i =0; i < num; i++){
ary[i]= i +1;}mydelete(1);show();mydelete(3);show();return0;}
插入
#include<iostream>usingnamespace std;int num;constint maxn =1000;int digit[maxn];voidshow(void){for(int i =0; i < num; i++){printf("%d%s", digit[i], i == num -1?"\n":" ");}}boolinsert(int index,int v){if(index == maxn -1||index<0||index>maxn||index>num){returnfalse;}else{for(int i = num -1; i >= index; i--){
digit[i +1]= digit[i];}
digit[index]= v;
num++;}returntrue;}intmain(void){
num =10;for(int i =0; i < num; i++){
digit[i]= i +1;}show();insert(0,4);show();insert(6,8);show();return0;}
数组的储存
#include<iostream>usingnamespace std;intmain(void){int size =10;int* a;
a =newint[size];printf("%p %p\n",&a, a);for(int i =0; i < size; i++){
a[i]= i;}for(int i =0; i <10; i++){printf("a[%d] = %d,&a[%d] = %p\n", i,*(a + i), i,&a[i]);}return0;}