Summary of the differences between Java and C++ (1)

1. Identifiers in java can have $.

2. The keyword of Boolean type in java is boolean, char type occupies 2 bytes and C++ occupies 1 byte.

3. Variables in java must be assigned before they are used. They will not be assigned automatically like C++, otherwise it will compile errors.

4. The boolean type in java is true or false, and cannot be replaced by 0 or 1.

5. The definition and initialization of arrays in java can be separated, but not in C++.

/*
java中
*/
int[] a;
a = new int[10];

/*
C++中是不允许上面那样写的
*/
int a[10];

6. When defining an array in java, if no assignment is performed, the integer will be initialized to 0, the floating point type will be initialized to 0.0, and the reference type will be initialized to null. In C++, the integer array will be initialized randomly when there is no assignment. .

7, the array name in java is a reference type, personal understanding is similar to pointers in C++, so int[] arr = new int[5]; arr = new int[50]; such statements are allowed in java.

8. In Java, you can use arrays as the return value of a function, but C++ cannot.

Guess you like

Origin blog.csdn.net/xiaoan08133192/article/details/108170588