用数据指针数组(链表更灵活,但需要内存管理的支持)操纵数据指针,非常简单。
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
char a[7][5] = {{1,2,3,0,0},{4,5,6,0,0},{0,0,0,0,0},{7,8,9,1,0},{1,3,5,0,0},{2,4,6,0,0},{3,5,7,0,0}};
char* b[7];
b[0] =(char*) &a[0];
b[1] =(char*) &a[1];
b[2] =(char*) &a[3];
b[3] =(char*) &a[4];
b[4] =(char*) &a[5];
b[5] =(char*) &a[6];
b[6] =(char*) &a[7];
for (int i=0; i<6; i++)
printf("%d \n", b[i][0]);
return 0;
} |