Yesterday I programmed a small piece of C ++ code that contains a loop and an array. In the program, I need to reset the array every time the loop starts. However, if I use
memset(sum,sizeof(sum),0);
Then the array will not reset for all 0. For this program, I used:
for (i=0;i<sizeof(sum)/sizeof(int);i++) sum[i]=0;
instead.
However, I think the loop is not as clear as the function, and this requires an additional variable, not to mention that it is uncool a million times than the wizardry memset () function. Could you guys enlighten me on this?
source share