Skip to content

Structs and typedef: . vs -> · ⁨结构体与 typedef:. 与 ->⁩

English

Grouping related data

  • A struct groups several values into one thing. A point has an x and a y; a rectangle has a width and a height.
  • Each value inside is called a member (or field). They can have different types.
  • Structs let you pass one tidy thing around instead of many loose variables.

中文

把相关的数据组合起来

  • 结构体把几个值组合成一个东西。一个点有 x 和 y;一个矩形有 width 和 height。
  • 里面的每个值叫做成员(或字段)。它们可以是不同的类型。
  • 结构体让你把一个整齐的东西传来传去,而不是一堆零散的变量。

一个带 x、y 的 Point 结构体;用 . 直接访问字段,用 -> 通过指针访问

Handout

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

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