Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a performance difference between assigning before returning and directly returning in C++?

Is there a performance difference between the two following functions, or is it handled by the compiler the same?

double f1(double a, double b) {
  return a + b;
}

double f2(double a, double b) {
  double sum = a + b;
  return sum;
}

Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is there a performance difference between the two following functions

One function contains two statements and the other contains one statement.

or is it handled by the compiler the same?

They can be. Both functions have identical observable behaviour, so they may produce an identical program.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading