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
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты