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) ;
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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes