To use auto a function's return type, every return statement must return the same type. - C++ Function

C++ examples for Function:Function Return

Description

To use auto a function's return type, every return statement must return the same type.

Demo Code

#include <iostream> 

auto findArea(int length, int width, int height) {
  return length * width * height;
}

int main()/* www . jav  a  2s . co m*/
{
  auto length = 50.0;
  auto width = 30.0;
  auto height = 3.5;

  auto area = findArea(length, width, height);

  std::cout << "Area: " << area << std::endl;
  return 0;
}

Related Tutorials