Home > Net >  Why does the direction of reading code by the compiler/computer change for different cases? (C langu
Why does the direction of reading code by the compiler/computer change for different cases? (C langu

Time:12-29

Why is it that the computer/compiler "reads"
a=b a
from right to left but not
float b=a 1.2, a=1.0?
Both lines of code being completely unrelated.

If the compiler does read from right to left then this: float a=1.0, b=a 1.2 should give an error because "a" hasn't been declared yet, right?

Is float a=1.0, b=a 1.2 logically correct or float b=a 1.2, a=1.0?

Background:
I am just starting out C programming, and this is my 3rd program after hello world. So please keep that in mind while answering. Thanks.

CodePudding user response:

The compiler does not 'read' in any particular direction -- the scope of a variable name starts at the declarator for the variable and extends to the end of the block containing the declaration (or the file if at global scope). So it includes both the initializer of the declarator and any subsequent declarators in the same declaration, and any subsequent declarations.

  • Related