b
is a pointer, so sizeof(b)
is the size of a pointer, most likely 4 or 8 on current systems. So you're only setting the first few bytes to 0, instead of the entire array.
If you had declared b
as an array, e.g.
int b[5];
then sizeof(b)
would be the size of the entire array, and your memset
would work as you expected.