gpt4 book ai didi

C - 是否有可能有一个返回 char * 或 int 的函数?

转载 作者:行者123 更新时间:2023-11-30 18:20:01 25 4
gpt4 key购买 nike

是否有可能让函数根据执行时发生的情况返回 int 或 char* ?我尝试过 void 但在编译时我收到很多警告

示例

void int_char(char *str)
{
if (I 'm matching a condition in my string)
return (str);
else
return (0);
}

我希望我说得足够清楚。PS:我是 C 编程初学者

最佳答案

设计此类函数的合理方法是:

char* get_buffer (const char *str)
{
if (I'm matching a condition in my string)
return buffer;
else
return NULL;
}

(假设 buffer 不是局部变量)

关于C - 是否有可能有一个返回 char * 或 int 的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34673489/

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