C Language Programming Advanced _ First week: Data type: integer type, floating-point type, enum type
1.0 Data Types
1.1 Integer type
1.2 Floating-point types
1.3 Logical Types
1.4 Type conversions and conditional operations
1.0 Data Types
1 integers
char (%c), short, int (%d), long (%ld), Long Long (C99)
2 floating point
Float (%f), double (%LF), long double (C99)
3 logic
BOOL (C99)
4 hands
5 Custom Types
The range of the number expressed: Char<short<int<float<double
sizeof is a static operator whose results are determined at compile time.
Do not operate in the parentheses of sizeof, these operations do not
1 #define_crt_secure_no_warnings2 3#include <stdio.h>4 5 Main ()6 {7 intA =6;8 9printf"sizeof (int) =%d\n",sizeof(int));Ten Oneprintf"sizeof (a) =%d\n",sizeof(a++));//sizeof is a static operator whose results are determined at compile time. A //Do not operate in the parentheses of sizeof, these operations do not - -printf"a=%d\n", a);//is still 6 the -printf"sizeof (a) =%d\n",sizeof(A +1.0));//8, change to double - -printf"a=%d\n", a);//is still 6 + -System"Pause"); +}
1.1 Integer type
Integer
Char:1 byte, 8 bit: -128~127
Short:2 bytes: -32768~32767
int: Depending on the compiler CPU, the usual meaning is 1 words
Long: Depending on the compiler CPU, the usual meaning is 1 words
Long Long:8 bytes
1 #define_crt_secure_no_warnings2 3#include <stdio.h>4 5 Main ()6 {7printf"sizeof (char) =%d\n",sizeof(Char));8 9printf"sizeof (short) =%d\n",sizeof( Short));Ten Oneprintf"sizeof (int) =%d\n",sizeof(int)); A -printf"sizeof (long) =%d\n",sizeof(Long)); - theprintf"sizeof (Long long) =%d\n",sizeof(Long Long)); - -System"Pause"); -}
sizeof (char) =1
sizeof (short) =2
sizeof (int) =4
sizeof (long) =4
sizeof (long Long) =8
Please press any key to continue ...
Range of integers
1 #define_crt_secure_no_warnings2 3#include <stdio.h>4#include <limits.h>5 6 Main ()7 {8 Charc =255;9 inti =255;Ten Oneprintf"c=%d,i=%d\n", C, i);//char out of range, so display-1 A -printf"%d,%d\n", Char_max, char_min);//127-128 - theSystem"Pause"); -}
Complement
0000 0001 (1) +1111 1111 (-1) = (1) 0000 0000
1111 1111 is regarded as pure binary, is 255, is treated as a complement is-1
Similarly, for-A, whose complement is 0-a, is actually 2^n-a,n is this type of bit number
1.2 Floating-point types
1.3 Logical Types
1.4 Type conversions and conditional operations
NetEase Cloud Classroom _c language programming first week: Data type: integer type, floating-point type, enum type