i am a java begineer and my confusion is:
in c++ we have seen that we can initiliaze the array just by writing this-
int a[5];
but in java we need new operator for array initilzation as-
int a[]=new int[5];
plz explain me in detail the reason for this???
iwannalearn 0 Newbie Poster
Recommended Answers
Jump to Postint 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[5] allocates memory in the heap for an array of 5 ints
so
…
All 4 Replies
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
sam.udo 0 Newbie Poster
jon.kiparsky 326 Posting Virtuoso
lisaroy1 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.