码迷,mamicode.com
首页 > 其他好文 > 详细

C之结构体

时间:2017-02-19 14:21:59      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:size   std   char s   main   highlight   blog   学习   oid   访问   

#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之结构体

标签:size   std   char s   main   highlight   blog   学习   oid   访问   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!