标签:c 结构体
C 结构体的定义
#include <stdio.h> struct student { int ID; char name[10]; int age; }; //注意这里的分号 int main() { // 初始化 struct student student1 = {1111,"Redhat",20}; struct student student2 = {.ID = 1111,.name = "Debian",.age = 20};//C99才有 struct student student3 = {1111,"BSD",.ID = 20,.age = 30}; //ID = 20 //使用 printf("%d,%s,%d \n",student1.ID,student1.name,student1.age); printf("%d,%s,%d \n",student2.ID,student2.name,student2.age); printf("%d,%s,%d \n",student3.ID,student3.name,student3.age); } chunli@ubuntu:~/pointer$ gcc -std=c99 main.c && ./a.out 1111,Redhat,20 1111,Debian,20 20,BSD,30
本文出自 “魂斗罗” 博客,请务必保留此出处http://990487026.blog.51cto.com/10133282/1782752
标签:c 结构体
原文地址:http://990487026.blog.51cto.com/10133282/1782752