该程序如何在currYear()之前执行函数birthYear()?

时间:2017-03-14 14:12:18

标签: c++

以下程序如何在currYear()之前执行函数birthYear()?我的理解是语句outputAge(age(currYear(),birthYear()))是第一个被执行的,因此,age(currYear(),birthYear())是第一个要执行的函数。如果是这样,函数currYear()应该在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;
}

0 个答案:

没有答案