Like in Java, there’s a way to set null values in array elements,
Integer[] arr = new Integer[5];
In here, arr is an Integer array with size 5 contains null by default
So can we do the same in C++?
>Solution :
In Java, Integer
is an object type, not a primitive type, so it’s allowable to to set one to null. C++ doesn’t have equivalent object types. A better analogue would be the following java:
int[] arr = new int[5];
Here you have a primitive int
type which can’t be set to a null value. In C++ it’s the same thing.
The closest you can do is set all values to 0 or some other sentinel value. Either that or create your own Integer
type which I wouldn’t advise.