I am guessing differences in the following two codes. The first one is in python and works just fine.Here it is:
>>> def foo():
if 1:
print "this is working"
n=6
print "the value of n is {0}".format(n)
>>> foo()
this is working
the value of n is 6
The second one is in c, i guess the way i want to implement both programs is same.Here it is:
void main(){
if(1){
printf("this is working");
int n=9;
}
printf("the value of n is %d",n);
}
n
goes undeclared
in the c code while it works good in python.
I know that in the c code n
has scope within the if block
.But why there is no as such scope issue in python. Do the variables inside a block { }
are stored in different memory stacks
in c while in python they are stored in function's memory stack
?.Correct me if i am wrong somewhere.
Regards.