answersLogoWhite

0

What is inner returns in c plus plus?

Updated: 10/24/2022
User Avatar

Wiki User

10y ago

Best Answer

Inner returns is not part of standard terminology, so it's difficult to say exactly what it means. It sounds as though it means a return statement other than the one that would typically appear as the final statement in a function. For instance:

int foo(int x)

{

if(!x)

return(-1); // inner return?

return(x*x); // typical return?

}

Differentiating return statements in this way is somewhat meaningless. All we're really saying is that the function has multiple return paths, in this case 2 distinct return paths. A more complex function might have several return paths, some more deeply nested than others, but it makes no real difference, so long as every reachable path has a return statement. In some cases, a function may not have a final return statement at all, simply because the function is guaranteed to never reach that point, because all possible routes through the function lead to an "inner" return path. For example:

int foo(int x)

{

if(!x)

return(-1);

switch(x)

{

case(1): return(x);

case(2): return(x*x);

default: return(x*x*x);

}

}

In the above example, there is no return statement before the final closing brace, because the code is guaranteed never to reach that point. All the return paths are "inner" returns.

We could just as easily write the exact same function as follows:

int foo(int x)

{

switch(x)

{

case(0): return(-1);

case(1): return(x);

case(2): return(x*x);

defaut: return(x*x*x);

}

}

Or this way:

int foo(int x)

{

switch(x)

{

case(0): return(-1);

case(1): return(x);

case(2): return(x*x);

}

return(x*x*x);

}

The logic is the same in each case, it's just a question of which is easier to read and understand. Out of all three, the second is perhaps the simplest to understand because all the logic is contained within the switch statement. But as far as the compiler is concerned, there should be no difference. A good optimiser should compile all three with exactly the same assembly instructions.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is inner returns in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What to do to change c to c plus plus in turbo c plus plus?

The first thing to do is wrap the C code so the compiler knows to treat it specifically as C rather than C++: // Include directives go here. #ifdef __cplusplus extern "C" { #endif // __cplusplus // C code goes here. #ifdef __cplusplus } #endif // __cplusplus Often that's all you need to do. However, be aware that C++ uses reserved keywords that C does not not know anything about, so if you have C variables named "this" or "class" or "virtual", etc, then you must rename them throughout the C code. C does not adhere to the strict type-safety in C++. Therefore all calls to malloc (which returns void*) need to be cast to the specific type. Also, be wary of implicit casts from int to enum. C++ does not support this, but C does. Also be aware of sizeof() differences. In C, sizeof(char) typically returns 4 (bytes), whereas in C++ it always returns 1 (byte).


Who invented c plus plus and when?

C++ was originally called 'C With Classes' in 1978, and was renamed by its developer, Bjarne Stroustrup, in 1983. The new name literally meant 'the successor to C', although it should really have been called ++C (prefix increment) rather than C++ (postfix increment), since the former returns C+1 (the successor to C), while the latter returns C.


Can you declare a method within a method in c or c plus plus?

C: there are no methods in C. C++: no.


What is the different of c and c plus plus?

c is procedure oriented and c++ is object oriented & much newer.


How A plus B plus C plus D plus 80 plus 90 equal to 100 what is the value of A B C and D?

If a + b + c + d + 80 + 90 = 100, then a + b + c + d = -70.

Related questions

Which function is used to determine the position of the put pointer in a file in c plus plus?

The function ftell returns the position of the file pointer for a file.


A equals 10 b equals a plus plus plus plus plus a?

In C/C++, this code int a = 5; return a+++++a; leads to error. However, writing int a = 5; return (a++ + ++a); returns 12. Note that in other languages "a=5; a+++++a" leads to different results :)


C plus plus program using function min that take three parameters of type int and returns the minimum of the three?

int min (int a, int b, int c) {if (a


What to do to change c to c plus plus in turbo c plus plus?

The first thing to do is wrap the C code so the compiler knows to treat it specifically as C rather than C++: // Include directives go here. #ifdef __cplusplus extern "C" { #endif // __cplusplus // C code goes here. #ifdef __cplusplus } #endif // __cplusplus Often that's all you need to do. However, be aware that C++ uses reserved keywords that C does not not know anything about, so if you have C variables named "this" or "class" or "virtual", etc, then you must rename them throughout the C code. C does not adhere to the strict type-safety in C++. Therefore all calls to malloc (which returns void*) need to be cast to the specific type. Also, be wary of implicit casts from int to enum. C++ does not support this, but C does. Also be aware of sizeof() differences. In C, sizeof(char) typically returns 4 (bytes), whereas in C++ it always returns 1 (byte).


How can a procedure be defined in C plus plus?

A procedure is simply a function in C++, therefore you define procedures just as you would any function. In some languages, a procedure is not a function as such, insofar as there is no return type. The C++ equivalent would therefore be a function that returns void.


How do you write the subscript in c plus plus code using Balaguruswamy edition?

Subscripts have not changed since C++ evolved from C. Given an array x, the subscript x[n] returns a reference to the n-1th element of x. Note that Balaguruswamy is a book writer, he has not released any edition of C++.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


What are the stages of production of a firm?

a]increasing marginal returns b]diminishing returns c]negative returns


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.