Always initialize your variables

Do yourself a favor: always, always initialize your variables. If you don’t, it’s guaranteed that one day, you’ll spend hours, if not days, debugging something (unexpected results, random crashes, …), only to eventually find out that the cause was an uninitialized variable. So spend a little bit of time now, to save yourself tons of time later.

NB: of courses, as always, there are exceptions:

  • classes can initialize themselves. It’s not always the case though, so don’t assume they do.
  • something, something optimization. But 1) that should be extremely rare, and 2) compilers are usually smart enough to remove a useless initialization on their own. So basically ignore that reason and initialize.

ive seen in another persons tutorials, you can use braced initialization for blank stuff…examples




this will allow you to set it in another area

Privacy & Terms