C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

#include

int main(){
int i;
for(i=0;i<4;i++){
int a=20;
printf("%d",a);
a++;
}
return 0;
}

A. 24 24 24 24 B. 20 20 20 20
C. 16 16 16 16 D. error

Answer: Option B
Explaination:

Variable declared inside the for loop block has scope only within that block. After the first iteration variable a becomes dead and it looses its incremented value. In second iteration variable a is again declared and initialized and so on.



Discussion

Your Comments Goes here...
NameDiscussion