danteDev danteDev - 4 months ago 7
C Question

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.

Can we do like this:

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

return initialize2();
}


in other c file

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

return 0;
}


Is this a proper way to do like this?

Answer

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.
}
Comments