1. 结构体地址:
2. 指针函数和指针函数
指针函数:int* func(int a,int b);
返回int *类型数据
函数指针:int (*func)(int x,int y);
func可以作为指针进行匹配的参数的指向
如
同时当指针函数重新声明则
结构体:
同时在实现
&取该函数的地址,前提需要强转类型
#include <stdio.h> #include <stdlib.h> #include <string.h> struct son { int money; }; struct dah { int money; }; struct father { struct son s; struct dah d; int money; }; int main(void) { struct father *fa; printf("the address of father %p the address of son %p \n",&fa,&fa->s); printf("the address of father %p the address of dah %p \n",&fa,&fa->d); return 0; }
struct son s; 作为一个结构体,在father 存放一个son结构体的整体内存大小数据也就是int 大小,4字节。 当struct son *s,则作为一个指针,在32位计算机上以4字节存现内存。
当然 struct son s的地址也就是father的首地址。
指针函数:int* func(int a,int b);
返回int *类型数据
函数指针:int (*func)(int x,int y);
func可以作为指针进行匹配的参数的指向
如
void running(); func = &running; (*func)(1,2);
结构体:
struct test{ void (*func)(void); }; set(struct test *t, void (*running)) { t->func = running; t->func(); }
void *running(); func = (void*)&running; func();
&取该函数的地址,前提需要强转类型
Life is mess, don't let mess mess us.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了