简体   繁体   English

返回功能而不是“0”或“变量”

[英]return to function instead of “0” or “variable ”

This is a theoretical question. 这是一个理论问题。 To understand further how a return statement at the end of a function can be manipulated. 进一步了解如何操作函数末尾的return语句。

Can we do like this: 我们可以这样做:

int intialize1()
{
    ...do smth;
    ...do smth;

    return initialize2();
}

in other c file 在其他c文件中

int initialize2()
{
   ...do other thing;
   ...do other thing;

   return 0;
}

Is this a proper way to do like this? 这是一个这样做的正确方法吗?

What you wrote is completely correct, frequently done, and functionally equivalent to: 你写的是完全正确的,经常做的,并且在功能上等同于:

int initialize1()
{
    ...do smth;
    ...do smth;

    int x_value;              // Create a place to store the return value
    x_value = initialize2();  // Get the result of the function, and store it.
    return x_value;           // Return the stored value.
}

从return语句调用函数是完全合法的,但是你必须确保两个函数的返回类型是一致的,并且没有数据截断或语义错误的隐式转换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM