C++ defines a set of primitive types that include the arithmetic types and a special type names void .

C++: Arithmetic Types
The integral types and char have signed and unsigned types.
char
char You should not use char , Please use the others. Which of the other two character representations is equivalent to char depends on the compiler.signed charunsigned charint , long , long long
signed [type] defaultunsigned [type]<aside> 💡 Deciding which Types to use
unsigned type when you know that the values cannot be negative.int or long long for integer arithmetic. short is usually too small and, in practice, long often has the same size as int. If your data values are larger than the minimum guaranteed size of an int , then use long long 。char or bool in arithmetic expressions. Use them only to hold characters or truth values.signed char or unsigned char .double for floating-point computations.
</aside>char Type in arithmetic expressionint main() {
unsigned char num1 = 1;
unsigned char num2 = 'a'; // 'a' is 97 is Ascii Table
int num3 = 2;
std::cout << num1 + num2 + num3 << std::endl; // print 100
return 0;
}
What are the differences between
int,long,long long, andshort? Between an unsigned and a signed type? Between afloatand adouble?
C++ guarantees short and int is at least 16 bits, long at least 32 bits, long long at least 64 bits.
The signed can represent positive numbers, negative numbers and zero, while unsigned can only represent numbers no less than zero.
The C and C++ standards do not specify the representation of float , double and long double. It is possible that all three implemented as IEEE double-precision. Nevertheless, for most architectures (gcc, MSVC; x86, x64, ARM) float is indeed a IEEE single-precision floating point number (binary32), and double is a IEEE double-precision floating point number (binary64).