top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When does the C++ compiler create temporary variables?

+1 vote
588 views
When does the C++ compiler create temporary variables?
posted Mar 20, 2015 by Emran

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

If the function parameter is a "const reference", the compiler generates temporary variables in the following 2 ways.

a) If the actual argument is the correct type, but it isn't Lvalue

double Cubes(const double & num)
{
numb = numb * numb * numb;
return numb;
}

double temp = 2.0;

double value = cubes(3.0 + temp); // the argument is said to be an expression ,not the Lvalue;

b) A type can be converted to the correct type

long temp = 3 L;

double value = cuberoot ( temp ) ; 
answer Mar 23, 2015 by Mohammed Hussain
Similar Questions
+3 votes

Where does the table variables and temporary tables exist in the memory, in memory or physical drive?

+2 votes

Below is the sample code, Where size of a is not defined at the time of compilation,
Then how compiler knows the size of a? If we run the same program in C then compilation will fail.

#include<iostream>
using namespace std;
main()
{
        string a;
        cin>>a;
        cout<<a;
}
0 votes

Which is the best practice for variable declaration within the function ? Or is it vary from one language to other one ?

...