Share quay lui c++,

#C ++, #back, #RetReat, #C ++ BackandretReat, #C ++ BackandretReatExample ** Back and Retreat trong C ++ **

Quay lại và rút lui là hai khái niệm quan trọng trong C ++.Chúng được sử dụng để kiểm soát dòng thực hiện của một chương trình.

**Mặt sau**

Từ khóa 'Back` được sử dụng để trả về từ một hàm.Nó có thể được sử dụng bên trong cơ thể chức năng hoặc là câu lệnh cuối cùng trong hàm.

`` `C ++
int add (int a, int b) {
trả lại A + B;
}

int main () {
int x = thêm (10, 20);
std :: cout << x << std :: endl;// In 30
trả lại 0;
}
`` `

Trong ví dụ trên, hàm `add` trả về tổng của` a` và `b`.Hàm `main` gọi hàm` add` và in giá trị được trả về.

**Rút lui**

Từ khóa 'Retreat` được sử dụng để nhảy vào nhãn trong mã.Nhãn là một vị trí được đặt tên trong mã có thể được sử dụng để nhảy đến.

`` `C ++
int main () {
int x = 10;
int y = 20;

if (x <y) {
nhãn tu một lần1;
}

std :: cout << "x lớn hơn y" << std :: endl;

Label1:
std :: cout << "x nhỏ hơn y" << std :: endl;

trả lại 0;
}
`` `

Trong ví dụ trên, từ khóa `Retreat` được sử dụng để nhảy vào nhãn` label1` nếu `x` nhỏ hơn` y`.Nếu `x` lớn hơn` y`, câu lệnh `retreat` bị bỏ qua và câu lệnh` std :: cout` được thực thi.

**Phần kết luận**

Quay lại và rút lui là hai khái niệm quan trọng trong C ++.Chúng được sử dụng để kiểm soát dòng thực hiện của một chương trình.Quay lại được sử dụng để trở về từ một chức năng, trong khi rút lui được sử dụng để nhảy vào nhãn trong mã.

** hashtags **

#C ++
#mặt sau
#rút lui
#C ++ BackandretReat
#C ++ BackandretReatExample
=======================================
#C++, #back, #RetReat, #c++backandretreat, #c++backandretreatexample **Back and Retreat in C++**

Back and retreat are two important concepts in C++. They are used to control the flow of execution of a program.

**Back**

The `back` keyword is used to return from a function. It can be used inside the function body or as the last statement in the function.

```c++
int add(int a, int b) {
return a + b;
}

int main() {
int x = add(10, 20);
std::cout << x << std::endl; // prints 30
return 0;
}
```

In the above example, the `add` function returns the sum of `a` and `b`. The `main` function calls the `add` function and prints the returned value.

**Retreat**

The `retreat` keyword is used to jump to a label in the code. The label is a named location in the code that can be used to jump to.

```c++
int main() {
int x = 10;
int y = 20;

if (x < y) {
retreat label1;
}

std::cout << "x is greater than y" << std::endl;

label1:
std::cout << "x is less than y" << std::endl;

return 0;
}
```

In the above example, the `retreat` keyword is used to jump to the label `label1` if `x` is less than `y`. If `x` is greater than `y`, the `retreat` statement is skipped and the `std::cout` statement is executed.

**Conclusion**

Back and retreat are two important concepts in C++. They are used to control the flow of execution of a program. Back is used to return from a function, while retreat is used to jump to a label in the code.

**Hashtags**

#C++
#back
#RetReat
#c++backandretreat
#c++backandretreatexample
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top