Question

What are the difference(s) between C/C++ arrays and Java arrays?. What are the differences(s) between C/C++...

What are the difference(s) between C/C++ arrays and Java arrays?.

What are the differences(s) between C/C++ and Java’s dynamic memory allocation?

What is the difference between pointer and reference in C++?

0 0
Add a comment Improve this question Transcribed image text
Answer #0

What is difference between arrays of C/C++ and Java:

In Java Array is an object and we can find the length of the array using member array.length() while in C++ it works differently as it its not an object

In Java array is dynamic, as we add more elements the size varies but in c++ the size is to be predefined.

Java can catch out of bounds exception , while in C++ we can not and the program may behave randomly if out of predefined bounds is called/

------------------------------------------------------------------

Difference between C++ and Java dynamic memory allocation

In C++ dynamic memory allocation is something programmer asks for in specific while writing the program using malloc and calloc and frees the space whenever required.Which can be used for temporary variables, when you are not aware of how much memory is required in prior.

While in Java all objects are dynamically created. It just creates a reference intially and allocates memory only after an object is initialized unlike in C++ where we have to decide upon static and dynamic memory while writing code.

--------------------------------------------------------------------------

difference between pointer and reference in C++:

If we declare a variable it needs some memory allocation

memory cells -each one byte in size and have a unique address

So any variable declared will have a unique address

for example we declared a variable as

int x=25 and lets assume it is stores in memory of address - x

int &a=x creates 'a' as reference of x, we are not creating a new memory here, but referencing a to the address of x.

We cannot change the reference while runtime

Pointer:

for the same example int x=25; &x gives the address of x

any variable pointing to its address is called pointer

p=&x

o find the value using p we de reference the p using *

*p gives value present in the address.

we can always change p to refer to a different address .

Add a comment
Know the answer?
Add Answer to:
What are the difference(s) between C/C++ arrays and Java arrays?. What are the differences(s) between C/C++...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT