gpt4 book ai didi

c - 函数指针 - 自动取消引用

转载 作者:太空狗 更新时间:2023-10-29 16:25:11 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How does dereferencing of a function pointer happen?

  void myprint(char* x) {
printf("%s\n", x);
}

int main() {
char* s = "hello";
void (*test)(char*);
void (*test2)(char*);

test = myprint;
test2 = &myprint;

test(s);
(*test)(s);
test2(s);
(*test2)(s);

}

任何人都可以向我解释为什么以上所有代码都有效吗? “你好”被打印了四次。通过应用函数指针,它是否隐式取消引用?基本上我想知道函数指针实际上是如何存储的,因为上面的内容有点令人困惑。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com