我担心的是我计算 td 结束的方式是正确的。这是最优的吗?有没有更好的 C 习惯来做这种事情?
#include <stdio.h>
int main() {
char td[][4] = { {0,1,2,3}, {4,5,6,7}, {8,9,10,11},
{12,13,14,15}, {16,17,18,19}, {20,21,22,23} };
char* p = *td;
int rows = sizeof(td) / sizeof(td[0]);
int cols = sizeof(td[0]) / sizeof(td[0][0]);
char* end = p + (rows * cols);
/* Print first element in each 'row' */
while(p != end) {
printf("first element: %u\n", p[0]);
p += 4;
}
return 0;
}