我正在尝试初始化一个结构数组。该结构包含所有整数值,我想将它们的初始值全部设置为 0。
首先我做了很长的路是这样的:
void initializeTcsPointer( TestCaseSet* tcsPointer )
{
for ( int i = 0; i < MAX_NUMBER_TEST_CASE_SETS; i++ )
{
tcsPointer[i].numPass = 0;
tcsPointer[i].numFail = 0;
tcsPointer[i].numPWU = 0;
tcsPointer[i].numFWU = 0;
tcsPointer[i].numRFA_Pass = 0;
tcsPointer[i].numRFB_Pass = 0;
tcsPointer[i].numRFA_PWU = 0;
tcsPointer[i].numRFB_PWU = 0;
tcsPointer[i].numRFA_FWU = 0;
tcsPointer[i].numRFB_FWU = 0;
tcsPointer[i].numRFA_Fail = 0;
tcsPointer[i].numRFB_Fail = 0;
}
}
它有效,但后来我想用简短的方式做到这一点:
void initializeTcsPointer( TestCaseSet* tcsPointer )
{
TestCaseSet newSet = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for ( int i = 0; i < MAX_NUMBER_TEST_CASE_SETS; i++ )
{
tcsPointer[i] = newSet;
}
}
这是行不通的。我想知道怎么来的?