1. 下标方式遍历数组:
void index_visit_array()
{
typedef struct tagNodeST
{
unsigned int uix;
float fy;
char cz;
int magic[4];
}NODE_ST;
NODE_ST astNodes[10];
int len = sizeof(astNodes) / sizeof(astNodes[0]);
//index way visit node element in array
for(int i = len; i--;)
{
astNodes[i].uix = 0;
astNodes[i].fy = 0.f;
astNodes[i].cz = 0;
}
return;
}
2.指针方式遍历数组
void pointer_visit_array()
{
typedef struct tagNodeST
{
unsigned int uix;
float fy;
char cz;
int magic[4];
}NODE_ST;
NODE_ST astNodes[10];
int len = sizeof(astNodes) / sizeof(astNodes[0]);
//pointer way visit node element in array
NODE_ST* start = astNodes;
const NODE_ST* const max = astNodes + len - 1;
while (start <= max)
{
start->uix = 0;//*(unsigned int*)start = 0;
start->fy = 0.f;
start->cz = 0;
++start;
}
return;
}
一般情况下可以使用指针遍历数组来代替下标遍历数组,提高性能。
(end)