int array[5] = {1,2,3,4,5}; //指定下标长度并初始化所有元素. int array[5] = {1,2,3}; //指定下标长度并初始化部分元素. 1,2,3,0,0 int array[] = {1,2,3,4,5}; //不指定下标长度并初始化所有元素. #include "stdafx.h" #include "iostream.h" #include "string.h" int main(int argc, char* argv[]) { char *array[3]; array[1] = new char[100]; strcpy(array[1], "创建指定大小的字符型数组"); cout << array[1] << endl; cout << *(array+1) << endl; delete [] array[1]; return 0; } #include "stdafx.h" #include "iostream.h" int main(int argc, char* argv[]) { int array[3] = {10,20,30}; for(int i=0;i<10;i++) cout << *(arrar+i) << " "; //通过指针输出数组 cout << endl; return 0; } //冒泡排序 #include "stdafx.h" #include "iostream.h" #include "string.h" #include "stdlib.h" int main(int argc, char* argv[]) { int i, flag, i2, j, t; int a[10]; int *p; int num=1; flag = 1; p = a; for(i=0;i<10;i++) { a[i] = rand()%100; } for(i2=0;i2<10;i2++) { cout << a[i2] << "\t"; //cout << *p++ << endl; } cout << "################" << endl; for(i=0;i<9;i++) { flag = 0; for(j=0;j<9;j++) { if(a[j]>a[j+1]) { num++; t = a[j]; a[j] = a[j+1]; a[j+1] = t; flag = 1; } } if(0 == flag) { break; } for(i2=0;i2<10;i2++) { cout << a[i2] << "\t"; //cout << *p++ << endl; } } for(i=0;i<10;i++) { //cout << a[i] << "\t"; cout << *p++ << endl; } cout << "num=" << num << endl; return 0; }