gpt4 book ai didi

C拼图: Output of printf should be '5' always

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

我在 C aptitude 论文中找到了这个谜题。

void change()
{
//write something in this function so that output of printf in main function
//should always give 5.you can't change the main function
}

int main()
{
int i = 5;
change();
i = 10;
printf("%d", i);
return 0;
}

有什么解决办法吗?

最佳答案

定义?

#include <stdio.h>

void change()
{
//write something in this function so that output of printf in main function
//should always give 5.you can't change the main function
#define printf_ printf
#define printf(a, b) printf_("5");
}

int main()
{
int i = 5;
change();
i = 10;
printf("%d", i);
return 0;
}

关于C拼图: Output of printf should be '5' always,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2182095/

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