c - What is the scope of variables, declared in a "for" condition? -


void main(void){     for(int i;;);     for(int i;;); } 

is valid c code? scope of i?

c99 6.8.5.3 the statement

the statement

for (clause-1 ;expression-2 ;expression-3 )statement 

behaves follows: expression expression-2 controlling expression evaluated before each execution of loop body. expression expression-3 evaluated void expression after each execution of loop body. if clause-1is declaration, scope of variables declares remainder of declaration , entire loop, including other 2 expressions; reached in order of execution before first evaluation of controlling expression. if clause-1 expression, evaluated void expression before first evaluation of controlling expression.

also note feature valid since c99. in other words, can't declare variable in first statement in for loop in c89.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -