3

The C language requires that all variables used in the program should be declared before any other statements.

Why was this of significance? Was it for readability? If it was for readability, then why don't other languages follow the same rule?

I personally prefer declaring all my variables at the very start.

Moderators: Please delete if this is off-topic or already been asked. I was just keen to know improve my knowledge. Thanks.

unwind
  • 391,730
  • 64
  • 469
  • 606
topgun_ivard
  • 8,376
  • 10
  • 38
  • 45
  • 4
    Not the current C Standard. In C99 variable declarations and code can be intermixed at will. – pmg Apr 19 '11 at 09:17
  • 3
    that's not mandated anymore in the `C99` standard. – Mat Apr 19 '11 at 09:17
  • 1
    C99 do not have this limitation. Also see: http://stackoverflow.com/questions/288441/variable-declaration-placement-in-c – Vijay Mathew Apr 19 '11 at 09:18
  • 3
    now it's not mandatory anymore. Anyway it wasn't for readability. C is a very old language and one of its peculiar features is that a C file can be compiled with just one parsing. I think that the earliest version of the language made the choice to declare variable at the beginning for simplify the parsing – Heisenbug Apr 19 '11 at 09:22
  • ahha! good to know...if one of you can answer back, I can then accept it :) thanks – topgun_ivard Apr 19 '11 at 09:32

1 Answers1

4

Like other people said in comments now it's not mandatory anymore. Anyway it wasn't for readability. C is a very old language and one of its peculiar features is that a C file can be compiled with just one parsing. I think that the earliest version of the language made the choice to declare variable at the beginning for simplify the parsing

Heisenbug
  • 38,762
  • 28
  • 132
  • 190