professorbrill's blog

By professorbrill, 11 years ago, In English

Has anyone ever got problems because of forgetting to initialize a global variable?

And should I always initialize a variable when I create it?

P.S. I am talking about C++. Are the global variables initialized with "zero" by default? Or it depends on the compiler?

  • Vote: I like it
  • +12
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +18 Vote: I do not like it

In C++, if you declare a global or static primitive type (int, double, bool, etc) it is set to zero. If it's local (declared inside a function), its value is undefined unless initialized.