構造体のメンバの初期化
明解C言語 入門編 > 12. 構造体 >
構造体のメンバの初期化
C
#include <stdio.h>
#include <string.h>struct gstudent
{
char name[20];
int height;
float weight;
};int main(int argc, char* argv[])
{
struct gstudent sanaka = {"Sanaka", 175, 60.5};printf("氏名:%s\n", sanaka.name);
printf("身長:%d\n", sanaka.height);
printf("体重:%f\n", sanaka.weight);return 0;
}
実行結果
T:\>lesson091\project1.exe
氏名:Sanaka
身長:175
体重:60.500000