What will be the output of the following code:

#include <iostream>

int foo ( int & x )
{
    return x*3 ;
}


int foo ( int x )
{
    return x*2 ;
}


int main()
{
    int intvar = 3 ;
    float floatvar = 10.84 ;
    std::cout << foo(2+intvar) << foo(floatvar) ;
}
Explanation
In both cases a temporary variable of type const int will be created.
The C++ standard prohibits modification of temporary variables, hence the first function will be omitted in both cases. The second function will create a copy of the passed in variable, hence, it will be called in both cases.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з C++
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести