About C++ basic knowledge, you must know these professional terms(5)

The road is hindered and long, and the line is coming. Keep your head down and work hard, if you don't call it, it's a blockbuster! Come on, Sao Nian!

1 Introduction

  Based on "C++ Primer Chinese Edition (5th Edition)", Chapter 5 "Sentences" summarized;

  Tip: Be good at using shortcut keys to quickly search for relevant content! Ctrl + F


2 summary

  The C++ language only provides limited statement types, most of them will affect the control flow of the program:

  • While, for and do while statements, perform alternative operations.
  • The if and switch statements provide a conditional branch structure.
  • The continue statement terminates the current iteration of the loop.
  • Break statement, exit the loop or switch statement.
  • The goto statement transfers control to a labeled statement.
  • try and catch enclose a sequence of statements that may throw an exception in curly braces to form a try statement block. The catch clause is responsible for handling exceptions thrown by the code.
  • The throw expression statement, which exists in the code block, transfers control to the relevant catch clause.
  • The return statement terminates the execution of the function. We will introduce the return statement in Chapter 6.

  In addition, there are expression statements and declaration statements. The expression statement is used to solve the expression. The declaration and definition of variables have been introduced in Chapter 2.


3 Glossary

  • 块(block)

  A sequence of zero or more sentences enclosed in curly braces. A block is also a statement, so as long as the statement can be used, a block can be used.

  • break 语句(break statement)

  Terminate the loop or switch statement closest to it. Control is transferred to the first statement after the loop or switch.

  • case 标签(case label)

  The constant expression immediately after the case keyword in the switch statement (see section 2.4.4, page 58) cannot have the same value for any two case labels in the same switch statement.

  • catch 子句(catch clause)

  It consists of three parts: the catch keyword, the exception declaration in parentheses, and a statement block. The code of the catch clause is responsible for handling the exception defined in the exception declaration.

  • 复合语句(compound statement)

  And block are synonymous.

  • continue 语句(continue statement)

  Terminate the current iteration of the loop closest to it. Control is transferred to the conditional part of the while or do while statement, or the next iteration of the range for loop, or the expression at the head of the traditional for loop.

  • 悬垂 else(dangling else)

  It is a common saying that refers to how to deal with the situation where there are more if branches than else branches in nested if statements. The C++ language stipulates that else should match the previous unmatched if. Using curly braces can hide the inner if statement, so that the programmer can better control which if else should be matched.

  • default 标签(default label)

  It is a special case label. When the value of the switch expression cannot match any case label, the program executes the content under the default label.

  • do while 语句(do while statement)

  Similar to the while statement, the difference is that the do while statement executes the loop body first, and then determines the condition. The loop body code will be executed at least once.

  • 异常类(exception class)

  It is a set of classes defined by the standard library to represent errors in the program. Table 5.1 (page 176) lists exception classes for different purposes.

  • 异常声明(exception declaration)

  The declaration in the catch clause specifies the types of exceptions that the catch clause can handle.

  • 异常处理代码(exception handler)

  After an exception is raised somewhere in the program, another code used to handle the exception. And catch clause are synonymous.

  • 异常安全(exception safe)

  It is a term that means that when an exception is thrown, the program can perform the correct behavior.

  • 表达式语句(expression statement)

  That is, an expression is followed by a semicolon to make the expression perform the evaluation process.

  • 控制流(flow of control)

  The execution path of the program.

  • for 语句(for statement)

  Provides iterative statements for iterative execution. It is often used to traverse a container or repeat calculation several times.

  • goto 语句(goto statement)

  Make control unconditionally transfer to a specified labeled statement in the same function. The goto statement is likely to cause confusion in the control flow of the program and should be prohibited.

  • if else 语句(if else statement)

  Judge the conditions and execute the statements of if branch or else branch according to the results.

  • if 语句(if statement)

  Judge the condition and execute the sentence selectively according to the result. If the condition is true, execute the code of the if branch; if the condition is false, control is transferred to the first statement after the if structure.

  • 带标签语句(labeled statement)

  Statements with labels in front. The so-called label refers to an identifier and a colon immediately following it. For the same identifier, it can be used for other purposes while being used as a label without interfering with each other.

  • 空语句(null statement)

  Statements that only contain a semicolon.

  • 引发(raise)

  The meaning is similar to throw. In the C++ language, it can be said that an exception is thrown or an exception is thrown.

  • 范围 for 语句(range for statement)

  Statements that iterate in a sequence.

  • switch 语句(switch statement)

  A conditional statement that first evaluates the value of the expression following the switch keyword. If the value of a case label is equal to the value of the expression, the program directly jumps over the previous code and starts execution from this case label. When all the case labels cannot be matched, if there is a default label, continue execution from the default label; if not, end the switch statement.

  • terminate

  Is a standard library function, called when the exception is not caught. terminate terminates the execution of the current program.

  • throw 表达式(throw expression)

  An expression that interrupts the current execution path. The throw expression throws an exception and transfers control to the nearest catch clause that can handle the exception.

  • try 语句块(try block)

  The block following the try keyword, and one or more catch clauses. If the code of the try block raises an exception and one of the catch clauses matches the exception type, the exception is handled by the catch clause. Otherwise, the exception will be handled by the peripheral try block, or the program will terminate.

  • while 语句(while statement)

  As long as the specified condition is true, the target statement will be executed iteratively. Depending on the true value of the condition, the loop may be executed multiple times, or it may not be executed once.

If the content of the article is wrong, please comment / private message a lot of advice! If you think the content of the article is not bad, remember to click the four links (like, bookmark, leave a message, follow), if you can click a follow, that is the greatest encouragement to me, and it will be the motivation for my creation, thank you !

Guess you like

Origin blog.csdn.net/fighting_boom/article/details/109018233