C语言结构体全通详解
来源:互联网 发布:windows网络编程第二版 编辑:程序博客网 时间:2024/06/18 14:50
#include <stdio.h>#include <stdlib.h>struct student{int num;char *tel;int *can;};struct test_pfun {int id;char name[10];int *age;struct student stu;struct student *pstu;int (*add) (int a,int b);int (*sub) (int a,int b);int (*mult) (int a,int b);};static int test_add(int a,int b){ return (a+b);}static int test_sub(int a,int b){ return (a-b);}static int test_mult(int a,int b){ return (a*b);}void print_uage(char *p){printf("%s <num1> <num2>\n ",p);}int cnt ,cnt1;struct student zhang = {.num = 2013,.tel ="114",.can = &cnt,};struct student zhang1 = {.num = 2014,.tel ="120",.can = &cnt1,}; int main(int argc,char **argv){int a ,b; struct test_pfun google[] = {[0] = { /* [0] is omissible */google[0].id = 10, /* google[0] is omissible */.name = "google",.sub =test_sub,.mult =test_mult,.age = &b,.pstu = &zhang,.stu={.num = 258,.tel = "110",},},{.id = 11,.name = "linux",.age = &a,.add =test_add,.pstu = &zhang1,.stu ={.num = 256,.tel = "119",},},} ;if(argc!=3){print_uage(argv[0]);return -1;}a=strtoul(argv[1],NULL,0);b=strtoul(argv[2],NULL,0);printf("a = %d b= %d \n",a,b);printf("a+b=%d\n",google[1].add(a,b));printf("a-b=%d\n",google[0].sub(a,b));printf("a*b=%d\n",google[0].mult(a,b));printf("google[0].id = %d google[1].id = %d\n",google[0].id ,google[1].id );printf("google[0].age = %d google[1].age = %d\n",*google[0].age ,*google[1].age);printf("google[0].name = %s google[1].name = %s\n",google[0].name ,google[1].name);printf("google[0].stu.num = %d google[0].stu.tel =%s\n",google[0].stu.num,google[0].stu.tel);printf("google[1].stu.num = %d google[1].stu.tel =%s\n",google[1].stu.num,google[1].stu.tel);printf("google[0].pstu->num = %d google[0].pstu->tel =%s google[0].pstu->can =%d\n",google[0].pstu->num,google[0].pstu->tel,*google[0].pstu->can);printf("google[1].pstu->num = %d google[1].pstu->tel =%s google[1].pstu->can =%d\n ",google[1].pstu->num,google[1].pstu->tel,*google[0].pstu->can);return 0;}
阅读全文
0 0
- C语言结构体全通详解
- c语言结构体详解
- C语言结构体详解
- C语言结构指针详解
- C语言结构体详解
- c语言结构体详解
- C语言结构与联合详解
- C语言结构指针详解(推荐)
- C语言中的结构和联合详解
- C语言结构体对齐问题详解
- C语言结构体对齐问题详解
- C语言结构体对齐详解
- C语言结构体对齐问题详解
- C语言中结构体详解
- C语言结构体对齐问题详解
- C语言结构体对齐问题详解
- C语言结构体对齐问题详解
- C语言中结构体详解
- LCA(最近公共祖先)Tarjan算法
- 设计模式-策略模式
- 个人对sendmessage理解
- 零基础学编程流程-成为自由人
- RYU REST API学习-调用示例
- C语言结构体全通详解
- ORA-12560:TNS: 协议适配器错误 问题解决
- okhttp网络请求简介
- Linux 命令大全
- HTTP状态码简介
- 解决华硕(AC1300 AC-55)无线网卡在Ubuntu掉线不能连接的问题.md
- MyBatis(5):MyBatis集成Spring事务管理(上)
- 1.2 c++_语句
- SDRAM和重定位