gpt4 book ai didi

c - 为什么要打印 g 两次?

转载 作者:行者123 更新时间:2023-12-05 08:45:16 27 4
gpt4 key购买 nike

谁能给我解释一下这个程序

#include <stdio.h>

void print(void)
{
printf("g");
}

int main()
{
void(*message)(void);

print(); // i have doubt here it g

message = print; // now here why it is printin g again

(*message)();

return 0;
}

这个程序首先带了一个void函数,就是printf,现在当我们进入main函数时,第一行表示指针信息这是无效的,之后没有得到补偿

最佳答案

您正在调用 print 两次:一次是直接调用:

print(); 

一旦通过一个函数指针:

message = print; 
(*message)();

关于c - 为什么要打印 g 两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73264303/

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