【问题标题】:Return from void function to another void function从 void 函数返回到另一个 void 函数
【发布时间】:2023-01-28 16:26:58
【问题描述】:
void reserve(int x)
{
    stream = begin;
    if (begin == NULL)
    {
        begin = stream = (struct room*)malloc(sizeof(struct room));
        details();
        stream->following = NULL;
        printf("\n\t room booking is successful!");

    
        x = stream->room_period;
        printf("\n\t your room period is: period-%d", x);
        stream->room_period = x;
        
        return;
        
    }

运行details()后,程序会自动继续运行还是需要加一些字??

【问题讨论】:

    标签: c syntax


    【解决方案1】:

    如果函数 detals() 终止(返回),则将运行以下行。

    在 C 中,我们不强制转换 void *,所以它应该是,我建议您使用变量而不是类型作为 sizeof 的参数:

            begin = stream = malloc(sizeof *begin);
    

    您的函数缺少 },因此无法按原样编译。

    【讨论】:

      【解决方案2】:

      void 函数不会返回任何东西给它的调用者,除了执行。

      所以details() 之后的代码将运行一次(如果)它返回。

      【讨论】:

        猜你喜欢
        • 2016-04-22
        • 2021-06-06
        • 2016-08-28
        • 1970-01-01
        • 2015-01-24
        • 1970-01-01
        • 2015-01-12
        • 1970-01-01
        • 2021-12-18
        相关资源
        最近更新 更多