Analogy is a good way to learn a new language, so let's look at the data types of C in the Java language.
C language provides a rich data type, the following chart can be a good representation of the C language of all the data types:
From this you can see that the C language provides Java the language does not have the structure, the common body and the pointer type, while the C language lacks the Boolean type in Java, namely the Boolean,c language and the Java difference also manifests in each type occupies the number of bits, concrete see:
Here are a few things to consider when using various types
1. Integral type
Integer constants have three decimal, octal, and hexadecimal digits in the C language. When used, the decimal number starts with a number other than 0, the octal number starts with 0, the hexadecimal digit starts with 0x, and the binary is converted to each other. For example you can direct printf("%d",0x567)
, other conversions and so on.
2, floating-point type
The use of floating-point types is double by default, and if you want to use float type, you should add F or f after the number.
Floating-point constants can be represented by exponents, and e to represent a power of 10, for example: 1.23e4=1.23*10^4.
When using the printf("%f",1.23456)
output, the default is to retain 6 digits after the decimal point, if you want to set yourself, you can use%.XF, where x represents the number of bits you want to output, such as printf("%.3f",1.2345)
will output 1.235.
Floating-point types are divided into two parts when the computer is stored: mantissa and exponent. The number of tails is the number of valid digits, the more the number of tail parts, the more accurate the numbers are expressed. The value range of the exponent is determined by the number of digits, the greater the number of values. The valid numbers for float and double are as follows:
3, Character type
Java uses 16-bit Unicode encoding to store numeric values of type char, while the C language uses 8-bit ASCII encoding for storage.
The C language is escaped with "\" as the escape character, and the detailed escape character list is as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Summary of C language data types