Which format is better in terms of speed, performance and machine code size?
Last return
is encapsulated:
static bool MyClass::IsEqual(int A, int B)
{
if (A == B)
{
return true;
}
else
{
return false;
}
}
Last return
is not encapsulated:
static bool MyClass::IsEqual(int A, int B)
{
if (A == B)
{
return true;
}
return false;
}
Which format is better in terms of speed, performance and machine code size?
They should all be identical or close to it. Moreover, you've asked the wrong question.
A better question would be,
Which should I prefer and why?
Bear in mind that C++ code was designed to be read by humans, not machines. Given this, a primary motive for selecting one coding style over another should be how readable it is to humans. As important as this consideration is, it's also unfortunately subjective. The bottom line is you have to decide for yourself which is better, but the important bit is that you're asking the right questions for the right reasons and thought about the answer.