i am a java begineer and my confusion is:
in c++ we have seen that we can initiliaze the array just by writing this-
but in java we need new operator for array initilzation as-
int a=new int;
plz explain me in detail the reason for this???
Jump to Post
int a (or int a ) defines a variable a that is a reference (like a pointer) to an array of ints. It's initial value is "null" - ie it does not contain an actual reference
new int allocates memory in the heap for an array of 5 ints
All 4 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.