主页
C 语言
C 结构体和指针
demo_structs_pointers
运行 ❯
×
更改方向
保存代码
更改主题
#include
// Define a struct struct Car { char brand[30]; int year; }; int main() { struct Car car = {"Toyota", 2020}; // Declare a pointer to the struct struct Car *ptr = &car; // Access members using the -> operator printf("Brand: %s\n", ptr->brand); printf("Year: %d\n", ptr->year); return 0; }
Brand: Toyota
Year: 2020