C语言基础:结构体初始化
#include <stdio.h> int main(void) { struct Shape { int type; int color; float radius; float area; float perimeter; } circle = {0, 1, 5.0, 78.37, 31.42}; printf("circle.type %d\n", circle.type); printf("circle.color %d\n", circle.color); printf("circle.radius %f circle.area %f circle.perimeter %f\n", circle.radius, circle.area, circle.perimeter); return 1; }
输出结果
circle.type 0 circle.color 1 circle.radius 5.000000 circle.area 78.370003 circle.perimeter 31.420000