PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] Why does the direction of reading code by the compiler/computer change for different cases? (C language)

 June 26, 2022     c, compiler-errors     No comments   

Issue

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.


Solution

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.



Answered By - Chris Dodd
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing