首页 > 其他 > 详细

C之结构体

时间:2017-02-19 14:20:01      阅读:140      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<stdlib.h>
void study(){
    printf("好好学习,天天向上 \n");
}

//定义结构体 

//结构体中不能定义函数,但是可以定义函数指针 

struct student{
  int age;
  char sex;
  void(*study)();     
};

main(){
  struct student st = {20,‘f‘, study};
  printf("%d\n", st.age);
  //printf("结构体长度为%d\n", sizeof(st));
  //访问结构体的函数指针 
  st.study();
  struct student* stp = &st;        
  //引用结构体中的这个函数指针 ->左边必须是结构体的一级指针 
  stp->study();
}

 

 

C之结构体

原文:http://www.cnblogs.com/loaderman/p/6415535.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!