answersLogoWhite

0

There is no difference, other than that declarations in C++ can also initialise the variable in a single instruction.

C example:

int x; // declaration

x=5; // initialisation

C++ example:

int y=5; // declaration and initialisation combined.

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

Consider the following:

C++:

int* anArray;

anArray = new int[10];

delete[]anArray;

Java:

int[] anArray;

anArray = new int[10];

The only real difference is the type used to refer to the array. In C++, we use a primitive int pointer, but in Java, we use an int array reference. Note that all integrals are implemented as objects in Java, since there is no concept of a primitive. All this really means is that C++ programmers must return the memory back to the system whereas Java's garbage collection takes care of it for us.

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What are the difference between array declaration in java and c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp