0

How is that following program executes function birthYear() before currYear()? My understanding is that statement outputAge(age(currYear(), birthYear())) is the first to be executed, so, age(currYear(), birthYear()) is the first function to be executed. For been so, function currYear() should be executed before birthYear().

#include <iostream>

int currYear()
{
std::cout << "Enter current year: \n";
int currYear;
std::cin >> currYear;
return currYear;
}

int birthYear()
{
std::cout << "Enter year of birth: \n";
int birthYear;
std::cin >> birthYear;
return birthYear;
}

int age(int x, int y)
{
return x - y;
}

void outputAge(int x)
{
std::cout << "Age is:\n" << x << std::endl;
}

int main()
{
outputAge(age(currYear(), birthYear()));
return 0;
}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 3
    No, the order of evaluation of arguments is not mandatory. See http://en.cppreference.com/w/cpp/language/eval_order – Benoit Mar 14 '17 at 14:13
  • Can you explain why is that order your understanding? It would help answerer to pinpoint your misconception. – Vincent Savard Mar 14 '17 at 14:14
  • Please have a look into http://stackoverflow.com/questions/2934904/order-of-evaluation-in-c-function-parameters – RajeshDA Mar 14 '17 at 14:17
  • @ Mr. Benoit, Please accept my many thanks for you commented my question. I have learned from you that order of evaluation of arguments is not mandatory in C++. Regards. – George Theodosiou Mar 14 '17 at 14:34
  • Mr. Vincent Savard, please accept my many thanks for you commented my question. My answer to your question is that in english language we write from left to right. In other languages e.g. arabic, hebrew, they write from right to left. But C++ is written in english. Regards. – George Theodosiou Mar 14 '17 at 14:41
  • Mr. user1512 23, please accept my many thanks for you commented my question. Already I had a look into this question. My understanding is that Mr. Benoit said me. Regards. – George Theodosiou Mar 14 '17 at 14:44

0 Answers0