Home:ALL Converter>Why is const necessary here?

Why is const necessary here?

Ask Time:2017-06-15T22:17:20         Author:Carbon

Json Formatter

It makes some intuitive sense why const is necessary here, as the number hasn't really gotten a place to land so you can't pass it by reference, but is there a more formal explanation?

#include <iostream>

int number()
{
    return 8;
}

int greet(const int& q)
{
    std::cout << "HI!";
    return q;
}

int main()
{
    return greet(number());
}

Author:Carbon,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44569912/why-is-const-necessary-here
yy