C - Operators - Discussion

You Are Here :: Home > C > Operators - Discussion

 



Q.

What will be output if you will compile and execute the following c code?

#include
int main(){
int a=5;
int b=10;
{
int a=2;
a++;
b++;
}
printf("%d %d",a,b);
return 0;
}

A. 5 10 B. 6 11
C. 5 11 D. 6 10

Answer: Option C
Explaination:

 


Default storage class of local variable is auto. Scope and visibility of auto variable is within the block in which it has declared. In c, if there are two variables of the same name then we can access only local variable. Hence inside the inner block variable a is local variable which has declared and defined inside that block. When control comes out of the inner block local variable a became dead



Discussion

Your Comments Goes here...
NameDiscussion