Java and C ++ grammatical differences

zhaozj2021-02-16  64

1. Basic Type Automatic Conversion Automatic Conversion To meet the following two conditions: Type compatibility, target type range Source type big .short, byte, char will automatically convert to int When there is long, the operation result is converted to long when there is Double If it is converted to double when there is FLOAT, it is converted to FLOAT other type conversion to display conversion

2. The default non-integer constant in Java in Java is a Double type, so if you want to specify a float type integer, add F domain f, such as: float f = 3.2f;

3. The lifetime of the variable and the change in the changing life during Java are the definition of the statement block to the end of the statement block, and a variable name cannot be repeated in the same class. Such as public static void main (string [] args) {INT X; {INT X; // Here error, does not allow repeated definition, unlike C , hide the upper part of the same name variable INT B;} b = 2; // Here, Exceeding B's Life}

4. The logical constant is only true between the logical values ​​in Java, and the non-zero value in C is no longer used.

5. The irregular multi-dimensional array is not the concept of a multi-dimensional array in Java, and only array elements are also the concept of array types. At the same time, the size of the data is no longer ruled. Such as: int x [] [] = new int x [3] []; int x [0] = new int [3]; int x [1] = new int =; int x [2] = new int = 9]; can also define the array INT x [] [] = new int [3] [3] in type C ; the only thing to note that the size of the array cannot be specified when the array is defined. The initialization array can be used: int x [] = new int x [= {1, 3, 4} or int x [] = {1, 2, 3, 4}, int x [] [] = new int = [] {{1, 2, 3, 4}, {22, 4, 4}} Do not try to specify the size of the array, in Java, the array is an object, it has various methods and attributes Such as X.Length has the size of the array.

6. The logical operator adds a new operator in Java to add a new operator "|" and "&", they follow "||" and "&&" differences, the latter will be based on the value of the left operation. To decide whether to continue to perform the calculation of the following expression, if you can determine the result of the entire expression by passing the expression on the left, you will not be able to calculate other expressions. The former will calculate all expressions.

转载请注明原文地址:https://www.9cbs.com/read-20973.html

New Post(0)