Home > Back-end >  C language novice wondering about variable location
C language novice wondering about variable location

Time:10-09

Why all variables before the first for loop, can't run after the results? Hope the great god grant instruction!

CodePudding user response:

First because the sum has been accumulating (the last cycle is the result of the accumulation, so the if (sum==I) always not satisfied, so I didn't print

A second before each cycle to achieve I factor, the sum first, so the sum is I factor, so the if (sum==I) may meet, so there may be printing the results

CodePudding user response:

 
# define _CRT_SECURE_NO_WARNINGS
# include & lt; Stdio. H>
Int main ()
{
For (int I=0; I & lt; 10; I++)
{
Int j=10;
{
Printf (" % d \ n ", j++);
}
}
return 0;
}

Why j has been 10, define runs only once, isn't it? J is not in the block has been have a lifetime?

CodePudding user response:

reference 1st floor qybao response:
first because the sum has been accumulating (circulation is the result of the accumulation to last time), so the if (sum==I) always not satisfied, so I didn't print

A second before each cycle to achieve I factor, the sum first, so the sum is I factor, so the if (sum==I) may meet, so there may be the result printed

Understand understand, thank you!
  • Related