Simple variables in Java and C ++

I saw this sentence in some matrices:

"In Java, simple data types, such as int and char, work the same as in C."

I am wondering what they actually differ in Java and C ++?

In C ++, simple variables, such as primitives in Java, are assigned a memory address, so these primitive types in C ++ can have a pointer. However, Java primitives are not assigned a memory address, such as "Objects".

Am I right?

Thanks!

+5
source share
5 answers

Nearly.

In java primitives, memory is also assigned, but this happens internally and you cannot get the link.

The reason was security in memory management.

+7

Java ++, . , Java . . , Java Java Simple Types. , ++ , . ( , ) , . ++, , .

0

, .

  • Java ( char, , )
  • " " Java ( ) , .
  • char - C ( 8 ), Java 16 .
0

.

java () . //Infact, Java , .

Java. , , . -. -

.

.

0

.

int x = 5;
int y = x;

y++;

// y = 6
// x = 5

.

Object a = new Object();
Object b = a;

b.someAction();

// A and B point to the same object and both have had the 'someAction()' performed

, , , something

-1

All Articles