+ 1

What's recommended between these two variables declaration?

int sum = 0; int firstnumber = 1; int secondnumber = 2; int sum = 0, firstnumber = 1, secondnumber = 2;

15th Nov 2022, 6:14 AM
Mozzie
Mozzie - avatar
1 Resposta
+ 4
Please put the language in tags. Even if a certain language syntax allows you multiple ways to define variables, or do certain other things, there are conventions and style guides which were established over the years, by coding communities and companies. These conventions have one major goal: To make code EASY TO READ. Because typically, developers spend 10 times as much time with reading code than writing it. And mostly you would read someone else's code. So it helps a lot in comprehending the code intentions, if everyone follows the same style. So back to your question, it is typically recommended to declare each variable on a separate line. But this is just a tiny part of the style guide.
15th Nov 2022, 6:27 AM
Tibor Santa
Tibor Santa - avatar