c版的回调函数与c++版的虚函数
C语言的回调函数思想代码:
#include <stdio.h>
void *max(void *base, unsigned int nmemb, unsigned int size,
int (*compar)(const void *, const void *))
{
int i;
void* max_data = base;
char* tmp = base;
for (i=1; i<nmemb; i++) {
tmp = tmp + size;
if (compar(max_data, tmp) < 0) {
max_data = tmp;
}
}
return max_data;
}
int compar_int(const void* x, const void* y)
{
return (*(int*)x - *(int*)y);
}
typedef struct _Student {
char name[16];
int score;
} Student;
int compar_student(const void* x, const void* y)
{
return (((Student*)x)->score - ((Student*)y)->score);
}
int main()
{
int data_int[] = {3, 2, 56, 41, 22, 7};
unsigned int count_int = sizeof(data_int) / sizeof(int);
int* max_int = (int*)max(data_int, count_int, sizeof(int), &compar_int);
printf("max int: %d\n", *max_int);
Student data_student[] = {
{"Kate", 92},
{"Green", 85},
{"Jet", 77},
{"Larry",88},
};
unsigned int count_student = sizeof(data_student) / sizeof(Student);
Student* high_score = (Student*)max(data_student,
count_student, sizeof(Student), &compar_student);
printf("high score -- name:%s, score:%d\n", high_score->name, high_score->score);
相关文档:
W3C标准的HTML标签
按功能类别排列
DTD:指示在哪种 XHTML 1.0 DTD 中允许该标签。
S=Strict,严格类型, T=Transitional,过渡类型【最普遍】, F=Frameset,框架类型.
标签成对,xhtml是比html更严格,类似XML格式
标签描述DTD
<!DOCTYPE>
定义文档类型。
STF
<html>
定义 HTML 文档。
STF
< ......
一、基本知识
指针和引用的声明方式:
声明指针: char* pc;
声明引用: char c = 'A'
char& rc = c;
它们的区别:
①从现象上看,指针在运行时可以改变其所指向的值,而引用一旦和某个对象绑定后 ......
C/C++是最主要的编程语言。这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码 。这份清单提供了源代码的链接以及它们的小说明。我已尽力包括最佳的C/C++源代码的网站。这不是一个完整的清单,您有建议可以联系我,我将欢迎您的建 议,以进一步加强这方面的清单。
1、http://snippets.dzone.com/tag/c/&nbs ......
刚开始学C/C++时,一直对字符串处理函数一知半解,这里列举C/C++字符串处理函数,希望对初学者有一定的帮助。
C:
char st[100];
1. 字符串长度
strlen(st);
2. 字符串比较
strcmp(st1,st2);
strncmp(st1,st2,n); 把st1,st2的前n个进行比较。
3. 附加
& ......