Which is the optimized way?
1)
{
int a[100] = {0};
}
or 2)
{
int a[100];
memset(a,0,100);
}
Assembly code generated by the two approches differ by how many instructions ?
Which is the optimized way?
1)
{
int a[100] = {0};
}
or 2)
{
int a[100];
memset(a,0,100);
}
Assembly code generated by the two approches differ by how many instructions ?
They typically compile down to the same assembly code especially with optimizations turned on or, otherwise, with a simple loop (e.g rep stos
).
However, it depends on the context: you usually don't even need (although you think so) to zero an array.
I would definitely prefer the first version as it's less error prone and (imho) states clearly your intent.