CoryKramer's answer says it all. However, to avoid the confusion you are facing, I would prefer:
#include <iostream> using namespace std; int max(int a, int b){ if (a > b) { return a; } else { return b; } } int main() { cout << max(7, 4) << endl; return 0; }
Alternatively you can use:
return a > b ? a : b;
The last line is the so-called conditional expression (or "conditional statement"). If the phrase is before? right, does it return the part between? and :, otherwise it returns the part after :.
Explained in detail here .
source share