Tài Liệu Học Tập
No Result
View All Result
  • Đề Thi
  • Lớp 12
    • Lịch Sử Lớp 12
    • Địa Lí Lớp 12
    • Ngữ Văn Lớp 12
    • GD KTPL Lớp 12
    • Toán Lớp 12
    • Tiếng Anh Lớp 12
    • Hóa Học Lớp 12
    • Sinh Học Lớp 12
    • Vật Lí Lớp 12
  • Lớp 11
    • Toán Lớp 11
    • Ngữ Văn Lớp 11
    • Tiếng Anh Lớp 11
    • Hóa Học Lớp 11
    • Sinh Học Lớp 11
    • Vật Lí Lớp 11
    • Lịch Sử Lớp 11
    • Địa Lí Lớp 11
    • GDCD Lớp 11
  • Lớp 10
    • Toán Lớp 10
    • Ngữ Văn Lớp 10
    • Tiếng Anh Lớp 10
    • Hóa Học Lớp 10
    • Sinh Học Lớp 10
    • Vật Lí Lớp 10
    • Lịch Sử Lớp 10
    • Địa Lí Lớp 10
    • GDKTPL Lớp 10
    • Công nghệ lớp 10
    • Tin Học Lớp 10
  • Lớp 9
    • Toán Lớp 9
    • Ngữ Văn Lớp 9
    • Tiếng Anh Lớp 9
    • Lịch sử và địa lý lớp 9
    • Khoa Học Tự Nhiên Lớp 9
    • GDCD Lớp 9
  • Lớp 8
    • Toán Lớp 8
    • Ngữ Văn Lớp 8
    • Tiếng Anh Lớp 8
    • Lịch sử và địa lý lớp 8
    • Khoa Học Tự Nhiên Lớp 8
    • GDCD 8
  • Lớp 7
    • Toán Lớp 7
    • Văn Lớp 7
    • Tiếng Anh Lớp 7
    • Lịch Sử Và Địa Lí Lớp 7
    • Khoa Học Tự Nhiên Lớp 7
  • Lớp 6
    • Toán Lớp 6
    • Văn Lớp 6
    • Tiếng Anh lớp 6
    • Lịch Sử và Địa Lí Lớp 6
    • Khoa Học Tự Nhiên lớp 6
  • Lớp 5
    • Toán lớp 5
    • Tiếng Việt Lớp 5
    • Tiếng Anh Lớp 5
    • Lịch Sử và Địa Lí Lớp 5
  • Lớp 4
    • Toán lớp 4
    • Tiếng Việt Lớp 4
    • Tiếng Anh Lớp 4
    • Lịch Sử và Địa Lí Lớp 4
  • Lớp 3
    • Toán lớp 3
    • Tiếng Anh Lớp 3
    • Tiếng Việt Lớp 3
  • Mẹo Hay
  • Tin tức
  • Liên Hệ
Tài Liệu Học Tập
No Result
View All Result
Home chính tả

Switch statement

by Tranducdoan
27/12/2025
in chính tả
0
Đánh giá bài viết

Transfers control to one of several statements, depending on the value of a condition.

  • 1 Syntax
  • 2 Condition
    • 2.1 Expression
    • 2.2 Declaration
      • 2.2.1 Non-structured binding declaration
      • 2.2.2 Structured binding declaration
    • 2.3 Type
  • 3 Labels
  • 4 Control flow transfer
  • 5 switch statements with initializer
  • 6 Notes
  • 7 Keywords
  • 8 Example
  • 9 Defect reports
  • 10 See also
  • 11 External links

Mục Lục Bài Viết

  1. [edit] Syntax
  2. [edit] Condition
    1. [edit] Expression
    2. [edit] Declaration
      1. [edit] Non-structured binding declaration
      2. Structured binding declaration
    3. [edit] Type
  3. [edit] Labels
  4. [edit] Control flow transfer
  5. switch statements with initializer
  6. [edit] Notes
  7. [edit] Keywords
  8. [edit] Example
  9. [edit] Defect reports
  10. [edit] See also
  11. [edit] External links

[edit] Syntax

attr (optional) switch ( init-statement (optional) condition ) statement attr – (since C++11) any number of attributes init-statement – (since C++17) any of the following:

  • an expression statement (which may be a null statement 😉
  • a simple declaration, typically a declaration of a variable with initializer, but it may declare arbitrarily many variables or structured bindings
  • an alias declaration

(since C++23)

Note that any init-statement must end with a semicolon. This is why it is often described informally as an expression or a declaration followed by a semicolon.

condition – a condition statement – a statement (typically a compound statement)

[edit] Condition

A condition can either be an expression or a simple declaration.

  • If it can be syntactically resolved as a structured binding declaration, it is interpreted as a structured binding declaration.

(since C++26)

  • If it can be syntactically resolved as an expression, it is treated as an expression. Otherwise, it is treated as a declaration that is not a structured binding declaration(since C++26).

When control reaches condition, the condition will yield a value, which is used to determine which label the control will go to.

[edit] Expression

If condition is an expression, the value it yields is the the value of the expression.

[edit] Declaration

If condition is a simple declaration, the value it yields is the value of the decision variable (see below).

[edit] Non-structured binding declaration

The declaration has the following restrictions:

  • Syntactically conforms to the following form:
  • type-specifier-seq declarator = assignment-expression

(until C++11)

  • attribute-specifier-seq(optional) decl-specifier-seq declarator brace-or-equal-initializer

(since C++11)

  • The declarator cannot specify a function or an array.
  • The type specifier sequence(until C++11)declaration specifier sequence can only contain type specifiers and constexpr, and it(since C++11) cannot define a class or enumeration.

The decision variable of the declaration is the declared variable.

Structured binding declaration

The declaration has the following restrictions:

  • The expression in its initializer cannot be of an array type.
  • The declaration specifier sequence can only contain type specifiers and constexpr.

The decision variable of the declaration is the invented variable e introduced by the declaration.

(since C++26)

[edit] Type

condition can only yield the following types:

  • integral types
  • enumeration types
  • class types

If the yielded value is of a class type, it is contextually implicitly converted to an integral or enumeration type.

If the (possibly converted) type is subject to integral promotions , the yielded value is converted to the promoted type.

[edit] Labels

Any statement within the switch statement can be labeled with one or more following labels:

attr (optional) case constant-expression : (1) attr (optional) default: (2) attr – (since C++11) any number of attributes constant-expression – a converted constant expression of the adjusted type of the switch condition

A case or default label is associated with the innermost switch statement enclosing it.

If any of the following conditions is satisfied, the program is ill-formed:

  • A switch statement is associated with multiple case labels whose constant-expression s have the same value after conversions.
  • A switch statement is associated with multiple default labels.

[edit] Control flow transfer

When the condition of a switch statement yields a (possibly converted) value:

  • If one of the associated case label constants has the same value, control is passed to the statement labeled by the matched case label.
  • Otherwise, if there is an associated default label, control is passed to the statement labeled by the default label.
  • Otherwise, none of the statements in the switch statement will be executed.

case and default labels in themselves do not alter the flow of control. To exit from a switch statement from the middle, see break statements.

Compilers may issue warnings on fallthrough (reaching the next case or default label without a break) unless the attribute [[fallthrough]] appears immediately before the case label to indicate that the fallthrough is intentional(since C++17).

switch statements with initializer

If init-statement is used, the switch statement is equivalent to

{ init-statement switch ( condition ) statement

}

Except that names declared by the init-statement (if init-statement is a declaration) and names declared by condition (if condition is a declaration) are in the same scope, which is also the scope of statement.

(since C++17)

[edit] Notes

Because transfer of control is not permitted to enter the scope of a variable, if a declaration statement is encountered inside the statement, it has to be scoped in its own compound statement:

[edit] Keywords

switch, case, default

[edit] Example

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior CWG 1767 C++98 condition s of types that are not subject tointegral promotion could not be promoted do not promotecondition s of these types CWG 2629 C++98 condition could be a declaration of a floating-point variable prohibited

[edit] See also

[edit] External links

1. Loop unrolling using Duff’s Device 2. Duff’s device can be used to implement coroutines in C/C++

Previous Post

Sui gia hay Xui gia là đúng chính tả?

Next Post

Nỡ hay lỡ là đúng? Hai từ này tiếng Nghệ nói như thế nào?

Tranducdoan

Tranducdoan

Trần Đức Đoàn sinh năm 1999, anh chàng đẹp trai đến từ Thái Bình. Hiện đang theo học và làm việc tại trường cao đẳng FPT Polytechnic

Related Posts

Run tay – triệu chứng của bệnh gì?

by Tranducdoan
27/12/2025
0
0

Bài viết bởi Thạc sĩ, Bác sĩ Nguyễn Thị Minh Phương - Khoa Nội tổng hợp - Bệnh viện Đa...

KBS WORLD Vietnamese

by Tranducdoan
27/12/2025
0
0

Mẫu câu trong tuần섭섭하다 (Anh thấy tủi thân lắm đấy!)Phân tíchCâu nói dạng thân mật thể hiện sự buồn chán,...

Tuổi Đinh Mão 1987 năm nay bao nhiêu tuổi? Thi đại học năm nào?

by Tranducdoan
27/12/2025
0
0

Để biết người sinh năm 1987 năm nay bao nhiêu tuổi, thuộc mệnh gì cần dựa vào tử vi ngày...

“Trăm năm bia đá thì mòn, Ngàn năm bia miệng hãy còn trơ trơ”

by Tranducdoan
27/12/2025
0
0

"Trăm năm bia đá thì mòn, Ngàn năm bia miệng hãy còn trơ trơ" Nhà độc tài nào sau khi...

Load More
Next Post

Nỡ hay lỡ là đúng? Hai từ này tiếng Nghệ nói như thế nào?

  • Trending
  • Comments
  • Latest
File đề thi thử lịch sử thpt quốc gia 2024 2025 có đáp án

80 File đề thi thử lịch sử thpt quốc gia 2026 2025 có đáp án

16/12/2025
Viết bài văn kể lại câu chuyện về một nhân vật lịch sử mà em đã đọc đã nghe lớp 4 ngắn gọn

Kể lại câu chuyện về một nhân vật lịch sử lớp 4 ngắn gọn

27/03/2025
viet-bai-van-ke-ve-cau-chuyen-ma-em-yeu-thich-ngan-gon

Viết bài văn kể lại một câu chuyện ngắn gọn nhất 16 mẫu

16/11/2024
De Thi Cuoi Hoc Ki 1 Ngu Van 12 Nam 2021 2022 So Gddt Bac Giang Page 0001 Min

Đề thi học kì 1 lớp 12 môn văn năm học 2021-2022 tỉnh Bắc Giang

0
De Thi Cuoi Ki 1 Mon Van 9 Huyen Cu Chi 2022

Đề thi văn cuối kì 1 lớp 9 huyện Củ Chi năm học 2022 2023

0
Dự án tốt nghiệp FPT Polytechnic ngành Digital Marketing

Dự án tốt nghiệp FPT Polytechnic ngành Digital Marketing

0

Run tay – triệu chứng của bệnh gì?

27/12/2025

Trường THCS và THPT Phùng Hưng – Mái trường nuôi dưỡng nhân cách và khai mở trí tuệ

27/12/2025

KBS WORLD Vietnamese

27/12/2025
Xoilac TV trực tiếp bóng đá Socolive trực tiếp
Tài Liệu Học Tập

Copyright © 2022 Tài Liệu Học Tập.

Chuyên Mục

  • Đề Thi
  • Lớp 12
  • Lớp 11
  • Lớp 10
  • Lớp 9
  • Lớp 8
  • Lớp 7
  • Lớp 6
  • Lớp 5
  • Lớp 4
  • Lớp 3
  • Mẹo Hay
  • Tin tức
  • Liên Hệ

Tham Gia Group Tài Liệu Học Tập

No Result
View All Result
  • Đề Thi
  • Lớp 12
    • Lịch Sử Lớp 12
    • Địa Lí Lớp 12
    • Ngữ Văn Lớp 12
    • GD KTPL Lớp 12
    • Toán Lớp 12
    • Tiếng Anh Lớp 12
    • Hóa Học Lớp 12
    • Sinh Học Lớp 12
    • Vật Lí Lớp 12
  • Lớp 11
    • Toán Lớp 11
    • Ngữ Văn Lớp 11
    • Tiếng Anh Lớp 11
    • Hóa Học Lớp 11
    • Sinh Học Lớp 11
    • Vật Lí Lớp 11
    • Lịch Sử Lớp 11
    • Địa Lí Lớp 11
    • GDCD Lớp 11
  • Lớp 10
    • Toán Lớp 10
    • Ngữ Văn Lớp 10
    • Tiếng Anh Lớp 10
    • Hóa Học Lớp 10
    • Sinh Học Lớp 10
    • Vật Lí Lớp 10
    • Lịch Sử Lớp 10
    • Địa Lí Lớp 10
    • GDKTPL Lớp 10
    • Công nghệ lớp 10
    • Tin Học Lớp 10
  • Lớp 9
    • Toán Lớp 9
    • Ngữ Văn Lớp 9
    • Tiếng Anh Lớp 9
    • Lịch sử và địa lý lớp 9
    • Khoa Học Tự Nhiên Lớp 9
    • GDCD Lớp 9
  • Lớp 8
    • Toán Lớp 8
    • Ngữ Văn Lớp 8
    • Tiếng Anh Lớp 8
    • Lịch sử và địa lý lớp 8
    • Khoa Học Tự Nhiên Lớp 8
    • GDCD 8
  • Lớp 7
    • Toán Lớp 7
    • Văn Lớp 7
    • Tiếng Anh Lớp 7
    • Lịch Sử Và Địa Lí Lớp 7
    • Khoa Học Tự Nhiên Lớp 7
  • Lớp 6
    • Toán Lớp 6
    • Văn Lớp 6
    • Tiếng Anh lớp 6
    • Lịch Sử và Địa Lí Lớp 6
    • Khoa Học Tự Nhiên lớp 6
  • Lớp 5
    • Toán lớp 5
    • Tiếng Việt Lớp 5
    • Tiếng Anh Lớp 5
    • Lịch Sử và Địa Lí Lớp 5
  • Lớp 4
    • Toán lớp 4
    • Tiếng Việt Lớp 4
    • Tiếng Anh Lớp 4
    • Lịch Sử và Địa Lí Lớp 4
  • Lớp 3
    • Toán lớp 3
    • Tiếng Anh Lớp 3
    • Tiếng Việt Lớp 3
  • Mẹo Hay
  • Tin tức
  • Liên Hệ

Copyright © 2022 Tài Liệu Học Tập.