I have see some example like below in a different question which I have not seen before.
new int[m_size]();
^^
I have seen and used the version new int[m_size]
all the time but not one with the ()
at the end.
I have see some example like below in a different question which I have not seen before.
new int[m_size]();
^^
I have seen and used the version new int[m_size]
all the time but not one with the ()
at the end.
Two words : Value Initialization
new int[m_size]();
array elements would be zero-initialized by writing ()
because ()
implies value initialization.1 (zero initialization for a primitive type)
1: An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized. ( $8.5/7 )
it means all the elements will be zero initialized
,similar to calloc(o,sizeof(int))
where with this calloc ,ur initializing a single integer on heap with 0