I have few queries on allocation of var2
local variable, in reference to the below code.
When will the memory of a local variable
var2
allocated? Whethervar2
will be allocated whenever function is called or whenever condition is satisfied and control goes insideif(Threshold > 5)
?Does keeping
var2
within condition just only restrict the scope of local variable?Does keeping
var2
within condition improve processing speed as variable is not allocated and de-allocated every time function is called?
void fun1(int Threshold)
{
int var1 = 0;
if(Threshold > 5)
{
int var2 = 0;
}
}