Saturday, October 19, 2013

Initilization of variables with braces {}

Braces are used for initialization of arrays but can also be used for single variables. Apparently this helps prevent type conversion errors. The advantage of extending {} is to provide some consistency between initializing ordinary variables and class variables in c++ syntax.
int hamburgers = {24}; //not an array but a single value variable
int emus{7}; //you don't have to use an = sign
int rocs = {}; //if braces are empty sets to zero
int psychics{} // zero and you don't have to use an =

No comments:

Post a Comment