jeudi 19 décembre 2019

Difference between = and {} syntaxes for initializing a variable in C++

I have read quite a few C++ codes, and I have come across two methods of initialising a variable.

Method 1:

int score = 0;

Method 2:

int score {};

I know that int score {}; will initialise the score to 0, and so will int score = 0;

What is the difference between these two? I have read initialization: parenthesis vs. equals sign but that does not answer my question. I wish to know what is the difference between equal sign and curly brackets, not parenthesis. Which one should be used in which case?

Aucun commentaire:

Enregistrer un commentaire