Basics of C++ programming [1]

1. The development steps of a program

1. Edit program

Use a text editor to write and edit the program, and save the written program ( source file ) to the disk as the input of the editor

2. Compile the program

Translate source files into machine language by a compiler

3. Link program

The linker assembles system functions and functions in the source program into an executable file

4. Execute the program

Load the program into memory through the loader

5. Test

Program testing by building test cases

2. Basic code interpretation

1. Preprocessing directive (#include)

The preprocessor checks the preprocessing commands, then the compiler performs the operations required in the commands, then removes the preprocessing commands, and finally compiles

2. Block comments (/* */)

Block comments are used to display comments to users or code reviewers, and are completely ignored by the compiler

3. Line comments (//)

The entire line is ignored by the compiler

4.using namespace std

When an object has no last name, insert std:: in front of it, making its name complete

5.int main()

Every C++ program starts with the main function

6.{}

Curly braces must be paired, and every function definition must be enclosed within them

7.std::cin、std::cout、std::endl

std is the standard library, cout and endl are objects
. To avoid direction confusion, it can be simply understood as >> is input, data moves to the right, << is output, and data moves to the left. The
object of cin is the variable name, and the object of cout is the value

8.return 0

When the C++ runner waits and returns 0, the program runs successfully and ends the program

2. Variables, values, constants

1. Variables

Before using a variable, you must first define the variable, tell the compiler to use a memory location with a given name and a given type, and if the variable is declared without a given value, no value is stored

2. value

The content of the variable is called the "value"

3. Constants

The value of a constant cannot be changed. When declaring its memory location, use the const modifier to limit its name (it is not recommended to use literals)

Three, the components of a C++ program

1. Identifier

A C++ program without comments is a sequence of tokens. Tags contain identifiers, literals, or symbols

1. Identifier

Identifiers must start with a letter or underscore and can contain an unlimited number of numbers, letters or underscores
Identifiers can be attributed to keywords, predefined identifiers and user-defined identifiers

1. Keyword

Keyword cannot be redefined, keywordPlease add a picture description

2. Predefined identifiers

Do not change the predefined

3. User-defined identifier

If the identifier we define is descriptive, the name can describe the content of the entity

2. Literal

Literals are constant values ​​of different types, including integers, strings, etc.

3. Symbol

C++ uses non-alphabetic symbols as operators and punctuation marks, refer to the link

1. Arithmetic operators

insert image description here

2. Relational operators

insert image description here

3. Logical operators

insert image description here

4. Bitwise operators

insert image description here

5. Assignment operator

insert image description here

6. Miscellaneous operators

insert image description here

7. Operation priority

insert image description here

4. Data type

The data types are classified as follows and
insert image description here
the value ranges are as follows
insert image description here

1. Integer type

2. Character type

Character literals are always enclosed in single quotes

3. Boolean type

Boolean data types have a size of one byte

4. Floating point type

5. void type

6. String class

In C language, the string ends with a null character, the actual string length +1 (+'\0'), in C++ the string class is used, there is no null character

1. Why is the format of the C++ project .h, .cpp

The header file .h is

Source File

Guess you like

Origin blog.csdn.net/qq_37249793/article/details/130916019
Recommended