Skip to content

Booleans and selection: if, else, switch · ⁨布尔与选择:if、else、switch⁩

English

True and false in C

  • C has no separate true/false type by default. It uses numbers: 0 means false, and any other number means true.
  • A test like 5 > 3 produces 1 (true). 5 < 3 produces 0 (false).
  • (If you #include <stdbool.h> you can write bool, true, and false — but plain int works everywhere.)
中文

C 里的真与假

  • 默认情况下,C 没有单独的真/假类型。它用数字:0 表示假,任何其他数字表示真。
  • 像 5 > 3 这样的判断会得到 1(真)。5 < 3 会得到 0(假)。
  • (如果你 #include <stdbool.h>,就能写 bool、true、false —— 但普通的 int 在哪里都能用。)

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩