7
saas
5y

- int varX;
v/s
- int varX = 0;

makes a shit ton of difference ๐Ÿ˜–๐Ÿ˜–๐Ÿ˜–

Always remember to initialize.

Comments
  • 0
    @SevenDeadlyBugs go doesn't require one to initialize ๐Ÿคจ ?
  • 0
    What's the difference ? By default the variable set itself to a default value
  • 0
    @Mba3gar c and c++ don't. Dunno about any others ๐Ÿ˜…
  • 0
    @SevenDeadlyBugs it woeks in every single language i guess
  • 1
    @maushax that's why you always compile with -Werror ๐Ÿ‘
  • 4
    In C / C++, the variable will be initialised only if it's a global variable. A local variable will not be initialised, and it's actually bad practice to initialise everything "just in case".
  • 1
    @Fast-Nop yes, i forgot to mention the local scope ๐Ÿ˜…. Thanks.
  • 1
    And "not initialized" means that it well be some valid but unpredictable integer. Not null or undefined that you have in other languages :]
  • 1
    @Lensflare even better, if it's undefined anyway, the compiler can choose the fastest "undefined" and just optimise that shit away. Ideally the whole program.
Add Comment