Possible Duplicate:
Set all bytes of int to (unsigned char)0, guaranteed to represent zero?
I have the following anonymous union inside a struct:
union
{
unsigned value;
char name[4];
};
Can I replace the following code:
name[0] = 0;
name[1] = 0;
name[2] = 0;
name[3] = 0;
With the following code?
value = 0;
In your simple case it’s the same, but only because (most likely)
int(andunsignedis short forunsigned int) is 32 bits (i.e. four bytes). If the array is larger, orintis only 16 bits it will not be the same.