If I run following code, I get output
From inside innermost braces c is 5
from just outside innermost brace, c is 8
from inside function 48
From just before end of main c is 8
But if I change first line in if block to c = a + b; from int c = a + b;
I get output
From inside innermost braces c is 5
From just outside innermost brace, c is 5
from inside function 30
From just before end of main c is 5
My question is what determines penetrance of local variable in and out of the block?
#include <stdio.h>
void multiply (int a, int b, int c);
main ()
{
int a = 2, b = 3, c = 8;
if (a == 2)
{
int c = a + b;// if I make this statement as c = a+b,then next both printf will be both 5
printf ("\nFrom inside innermost braces c is %d\n",c);
}
printf("\nFrom just outside innermost brace, c is %d\n", c);
multiply (a,b,c);
printf ("\nFrom just before end of main c is %d\n",c);
}
void multiply (int a, int b, int c)
{
printf ("\nfrom inside function %d\n", a*b*c);
}