Why do we write sizeof(x) / sizeof(x[0]) instead of simply writing sizeof(x) to determine the size of the array in C++
I was expecting it to give correct output if we will write only sizeof(x) to find the size of the array.
>Solution :
Because sizeof uses units of bytes, not objects. These days, for array’s it’s better to just use std::extent to get array dimensions (the linked page includes examples). Separately, there was no need for parentheses when the argument is an object, so sizeof x / sizeof x[0] suffices. Parentheses are needed for types.