Home > Back-end >  The for statement I have any questions? Error message will not be able to define the I
The for statement I have any questions? Error message will not be able to define the I

Time:09-21

Help you big brother, I also not appeared for the first time, this situation is very unusual, ask a bosses to explain,

CodePudding user response:

Int I wrote two times, the line 9 comments

CodePudding user response:

Or wrong, and that's not the question int I

CodePudding user response:

You this is a c or c + +, c is not allowed to define int I for loop

CodePudding user response:




reference soul L reply: 3/f
you is this a c or c + +, c is not allowed to define the for loop int I right

C can also ah, unless it is old compiler

CodePudding user response:

Your compiler support for (int I=0) This kind of writing?

CodePudding user response:

Declare variable I in advance, in the for statement statement I=0 is the method of c + +

CodePudding user response:

refer to 6th floor Arthur169 response:
statement variable I in advance, in the for statement statement I=0 is the method of c + +

Talk nonsense!
The for loop
C C language statement
Perform cycle,

Used as a short equivalent version of the while loop,

Syntax
For (initial, anti-fuzzy sentences; Conditional expression; Iterative expressions) loop statement
Interpret
Performance is as follows:

Initial anti-fuzzy sentences can be declared for the expression or
If it is expression, before the first evaluated conditional expression will evaluate it once, and give up as a result,
(C99) if it is a statement, then its circulation throughout the body are in the scope, the rest of the anti-fuzzy including initial sentence, the conditional expression, the iterative formula and the loop statement, the statement in the declaration of variables are only allowed to have auto and the register storage class,
Conditional expression in circulation devices for evaluation, if the result of the expression is zero, the circular immediately exit,
After iterative expressions in the loop body evaluation, and abandon the result, evaluated after iterative expressions, transfers control to the conditional expression,
Initial changes, conditional expressions and iterative expressions are optional:

For (;; ) {
Printf (" endless loop!" );
}
Loop statement is not optional, but it can be a null statement:

For (int n=0; N & lt; 10; + + n, printf (" % d \ n ", n))
;//null statement
If need to terminate the loop execution in some point, can be in the loop of any location using the break statement,

Looping statements in any location using the continue statement will transfer control to the iterative expressions,

If an infinite loop in the conditional expression, iterative expressions or any part of the loop statement is observed behavior (I/O, volatile access, atoms or synchronous operation), has the cycle program has undefined behavior, this allows the compiler to optimize away the whole observation cycle, without having to prove that they will end, the only exception is the conditional expression is ignored or for the cycle of constant expressions: for (;; ) is always an infinite loop,

With all options and iteration statement, for statement building block scope: any initial changes in sentence, conditional expressions or iterative expressions away after the introduction of the identifier in the loop of scope,

(C99)
Keywords
For

Annotation
Used as a loop statement expression statement to establish its own, different from the initial changes scope block scope, unlike c + + :

for (int i=0; ; ) {
Long I=1;//legal in C, C + + illegal
//...
}
Can use goto into the loop body, on the way into the loop, anti-fuzzy does not perform the initial sentence and conditional expression, (if arrived control loop body tail, the possible including the use of conditional expression repeat,)

Example
Run the code
#include
#include
Enum {8} SIZE=;
Int main (void)
{
An int array [SIZE];
For (size_t I=0; I & lt; The SIZE; + + I)
Array [I]=rand () % 2;
Printf (" Array filled! \n");
For (size_t I=0; I & lt; The SIZE; + + I)
Printf (" % d ", array [I]);
printf("\n");
}
Possible output:

Array filled!
1 0 1 1 1 1 0 0
Refer to
C11 standard (ISO/IEC 9899:2011) :
6.8.5.3 The for statement (p: 151)
C99 standard (ISO/IEC 9899:1999) :
6.8.5.3 The for statement (p: 136)
C89/C90 standard (ISO/IEC 9899:1990) :
3.6.5.3 The for statement

CodePudding user response:

C99 does not support the for (int I) this kind of writing,

CodePudding user response:

The
8/f, 5250 references reply:
c99 does not support the for (int I) this kind of writing,

You said more than 10 years, c89 does not support, c99 support

CodePudding user response:

references 9/f, the truth is right or wrong response:
Quote: refer to the eighth floor 5250 response:

C99 does not support the for (int I) this kind of writing,

You said more than 10 years, c89 does not support, support c99



I was wrong. Thanks

CodePudding user response:

refer to 7th floor truth is right or wrong response:
Quote: refer to the sixth floor Arthur169 response:

Declare variable I in advance, in the for statement statement I=0 is the method of c + +

Talk nonsense!
The for loop
C C language statement
Perform cycle,

Used as a short equivalent version of the while loop,

Syntax
For (initial, anti-fuzzy sentences; Conditional expression; Iterative expressions) loop statement
Interpret
Performance is as follows:

Initial anti-fuzzy sentences can be declared for the expression or
If it is expression, before the first evaluated conditional expression will evaluate it once, and give up as a result,
(C99) if it is a statement, then its circulation throughout the body are in the scope, the rest of the anti-fuzzy including initial sentence, the conditional expression, the iterative formula and the loop statement, the statement in the declaration of variables are only allowed to have auto and the register storage class,
Conditional expression in circulation devices for evaluation, if the result of the expression is zero, the circular immediately exit,
After iterative expressions in the loop body evaluation, and abandon the result, evaluated after iterative expressions, transfers control to the conditional expression,
Initial changes, conditional expressions and iterative expressions are optional:

For (;; ) {
Printf (" endless loop!" );
}
Loop statement is not optional, but it can be a null statement:

For (int n=0; N & lt; 10; + + n, printf (" % d \ n ", n))
;//null statement
If need to terminate the loop execution in some point, can be in the loop of any location using the break statement,

Looping statements in any location using the continue statement will transfer control to the iterative expressions,

If an infinite loop in the conditional expression, iterative expressions or any part of the loop statement is observed behavior (I/O, volatile access, atoms or synchronous operation), has the cycle program has undefined behavior, this allows the compiler to optimize away the whole observation cycle, without having to prove that they will end, the only exception is the conditional expression is ignored or for the cycle of constant expressions: for (;; ) is always an infinite loop,

With all options and iteration statement, for statement building block scope: any initial changes in sentence, conditional expressions or iterative expressions away after the introduction of the identifier in the loop of scope,

(C99)
Keywords
For

Annotation
Used as a loop statement expression statement to establish its own, different from the initial changes scope block scope, unlike c + + :

for (int i=0; ; ) {
Long I=1;//legal in C, C + + illegal
//...
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related