#include <stdio.h>
void Print_Array(void *Array, int eleSize, int len, void(*print)(void *)) { char *start = (char *)Array; for (int x = 0; x < len; ++x) { print(start + x * eleSize); } }
void MyPrint(void *recv) { int *ptr = (int*)recv; printf("回调函数 --> 输出地址: %x --> 数据: %d \n", ptr,*ptr); }
void MyPrintPerson(void *recv) { struct Person *stu = (struct Person *)recv; printf("回调函数 --> 输出地址: %x \n", stu); }
int main(int argc, char* argv[]) { int arry[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; Print_Array(arry, sizeof(int), 10, MyPrint);
struct Person { char name[64]; int age; };
struct Person stu[] = { { "admin", 22 }, { "root", 33 } }; Print_Array(stu, sizeof(struct Person), 2, MyPrintPerson);
system("pause"); return 0; }
|