在 Linux 内核代码,特别是驱动代码中经常见到的用法是使用一个标准结构,后面的代码基于这个结构来实现,类似面向对象的多态特性。
在 C 语言里面借助结构体和函数指针实现的这个功能,这里我们写了个例子,提取了关键代码:
#include
struct s_new{
char name[10];
char* (* my_method)(char *name);...
分类:
系统相关 时间:
2014-05-23 07:58:18
阅读次数:
324
Football Score
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2579 Accepted Submission(s): 729
Problem Description
Football is on...
分类:
其他好文 时间:
2014-05-22 12:45:13
阅读次数:
291
结构的定义定义一个结构的一般形式为:struct结构名{成员表列}例如:struct
stu{int num;char name[20];int
age;}结构类型变量的说明结构体定义并不是定义一个变量,而是定义了一种数据类型,这种类型是你定义的,它可以和语言本身所自有的简单数据类型一样使用(如in...
分类:
其他好文 时间:
2014-05-22 05:36:40
阅读次数:
172
笔试遇到很多sizeof的小题,博主基础堪忧,怒总结如下,还是要巩固基础啊啊啊!sizeof操作符
对象所占内存空间的大小,单位是字节关键词:char 数组 指针 结构体sizeof(NULL)
结果为11.基本类型占内存大小32位机64位机器类型字节数int4char1指针48float4浮点型l...
分类:
编程语言 时间:
2014-05-22 04:55:18
阅读次数:
299
背景
C89标准规定初始化语句的元素以固定顺序出现,该顺序即待初始化数组或结构体元素的定义顺序。 C99标准新增指定初始化(Designated
Initializer),即可按照任意顺序对数组某些元素或结构体某些成员进行选择性初始化,只需指明它们所对应的数组下标或结构体成员名。GNU C将其作.....
分类:
其他好文 时间:
2014-05-21 21:53:54
阅读次数:
448
在C++中struct类型(结构体)属于类类型。 class student {} 与
strcut student
{}是一样的,唯一的区别就是class中如果未对成员进行public、private或protected等访问限定声明则默认为private的,而struct中则默认为publ...
分类:
编程语言 时间:
2014-05-21 17:55:05
阅读次数:
231
编程题:展示对整个结构体变量的引用的其他方法。功能:对整个结构体变量进行操作。#include<stdio.h>voidmain(){structperson{charname[20];charsex;structdate {intyear; intmonth; intday; }birthday; floatheight;}per1,per2={"LiPing","M",2013,12,15,175.5};per1=p..
分类:
其他好文 时间:
2014-05-21 00:20:43
阅读次数:
249
编程题:结构体数组的引用。功能:输出结构体数组各元素的成员值#include<stdio.h>voidmain(){structperson{charname[20];charsex;intage;floatheight;}per[3]={{"LiPing",‘M‘,20,175},{"WangLing",‘F‘,19,162.5},{"ZhaoHui",‘M‘,20,178}};inti;for(i=0;i<3;i++)print..
分类:
其他好文 时间:
2014-05-20 21:31:06
阅读次数:
336
编程题:指针变量指向结构体数组。#include<stdio.h>voidmain(){structperson{charname[20];charsex;intage;floatheight;}per[3]={{"LiPing",‘M‘,20,175},{"WangLing",‘F‘,19,162.5},{"ZhaoHui",‘M‘,20,178}};structperson*p;for(p=per;p<per+3;p++)printf("%-18s%3c%..
分类:
其他好文 时间:
2014-05-20 18:57:32
阅读次数:
255
编程题:对结构体变量中成员的引用展示。#include<stdio.h>voidmain(){structperson{charname[20];charsex;structdate {intyear; intmonth; intday; }birthday; floatheight;}per;printf("Enterthename:");gets(per.name);per.sex=‘M‘;per.birthday.year=2013;per.birthd..
分类:
其他好文 时间:
2014-05-20 18:41:16
阅读次数:
360