Generally speaking, if you want to get started in the C++ development industry, then the basic knowledge of C++ development must be understood. To get started in C++ development, you need to understand C++ data types and constant information.

1. The integer:

C++ integer types are divided into longint, basic int and shortint. Longint can be shortened to long, and shortint to short. Short int long or less or less

2. Floating point:

C++ floating point type is also known as real type, divided into single precision (float), double and longdouble (longdouble) three kinds. In C++, float takes up four bytes in memory and provides seven significant digits. Double and longdouble occupy 8 bytes in memory and provide 16 significant digits.

Because floating-point data is of finite length, floating-point numbers are subject to computational error. The more accurate the floating-point number is, the more accurate the result will be, but the processing time will be longer. When a large floating-point number is added to a small floating-point number, the accuracy limitation makes the small floating-point number ignored, making the addition meaningless.

#include <iostream> #include <iomanip> using namespace std; Int main() {float a=0.00000678f; Double b = 0.0000678; A = a + 111111.111 f; B = b + 111111.111; cout<<setiosflags(ios::fixed)<<setprecision(16); cout<<"a="<<a<<",b="<<b<<endl; return 0; }Copy the code

3. Character

In C++, there are two types of characters: signedchar and unsignedchar. Signed char can be ignored when written. Character data occupies one byte in memory and is stored in binary format.

Character data and integer data are common in C++. A character data can be assigned to an integer variable, an integer data can be assigned to a character variable, and an arithmetic operation can be performed on character data.

#include <iostream> using namespace std; int main() { int i,j; char c1,c2; c1='a'; // Assign character data to character type c2=98; // Assign integer data to character type I ='A'; // Assign character data to the integer j=66; / / integer data assigned to integer cout < < "I =" < < < < I, j = "" < < < < j, c1 =" "< < c1 < <", c2 = "< < c2 < < endl; cout<<"c1-32="<<c1-32<<endl; // return 0; }Copy the code

constant

1. Integer constants:

Decimal integer octal integer an integer that starts with 0 and consists of an octal number from 0 to 7, for example, 012,0177

Hexadecimal integer A hexadecimal integer starting with 0x or 0x and consisting of 0, 9, A, F, or A to F, for example, 0x1234, 0xab

2. Floating point constants:

In decimal form. A floating point number consisting of a decimal point, decimal integer, and decimal number. Integers and decimals can be omitted, but not the decimal exponent, also known as scientific notation. A floating point number in fEn or fEn format, where E or E represents a power base 10, f can be an integer or decimal, and n is an exponent and must be an integer

Floating-point constants default to double. A floating-point number is of type float if it is followed by an f or f.

3. Character constants:

A character enclosed in a pair of single quotation marks (“) represents a character constant A character constant represents a character and stores its ASCII code value. For example, ‘A’ represents the English character A, and the data value is 65. The ‘2’ represents the numeric character 2 and the data value is 50

4. Use escape characters to represent character constants:

Characters beginning with a backslash (\) followed by a sequence of one or more characters are called escape characters, such as \n for a newline character. Escape characters can be used to represent control characters or other special-purpose characters in the ASCII character set that are not printable or inconvenient to enter.

5. String constants:

A sequence of zero or more characters enclosed in double quotation marks (“”) is called a string constant. A string can be composed of either the ASCII character set or multi-byte character set (such as Chinese characters, Japanese and Korean characters, etc.)

Double quotes are delimiters of string constants, not part of the string. If double quotes occur in a string, use the escape character (“).

6. Symbolic constants:

Symbolic constants are defined in the form #define identifier constants. Where #define is the macro definition command, the function is to define the identifier as a constant value, in all the program where the identifier is replaced by a constant.

#include<iostream> usingnamespacestd; # definePI3.1415926 intmain () {doubler = 5.0; cout<<"L="<<2*PI*r<<",S="<<PI*r*r<<endl; return0; }Copy the code

Quantities whose values can change during the run of a program are called variables. A variable is essentially a unit of memory in a computer. The C++ language specifies that a variable should have a name that represents a location of memory.

Finally, it is also very important to ask big gods when you encounter problems.I suggest joining this group to chatYou will also get a lot of help if you discuss with your predecessors. Can also exchange learning experience, technical problems, you can get PDF books source code, tutorials and so on for free use.