+ 1

Why in most of programming languages declaration statement is done in the beginning of program?

Principal of programming languages

28th Jul 2019, 3:01 AM
Kunal Acharya
Kunal Acharya - avatar
3 Antworten
+ 8
Well, we obviously don't do them at the end of the program, since constructs are declared before use and not after use. It is also a good practice to group declarations together so that you don't have to go all over your code to search for a missing declaration later on.
28th Jul 2019, 3:08 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
You can declare them at time of use, but that gets messy really fast. Its important to keep your code tidy and structured and easy to read otherwise the bigger it gets, the more time you’re going to waste looking for variables scattered throughout your code rather than a nice organized list of them in a certain location. As Hatsy said, it is good practice.
28th Jul 2019, 3:29 AM
Jake
Jake - avatar
0
But we can also declare variable at time of it's use.like in c++
28th Jul 2019, 3:11 AM
Kunal Acharya
Kunal Acharya - avatar