Akilan Arasu
Akilan Arasu

Reputation: 350

Not able to understand declaration in c++

I am not able to understand what this declaration does in C++? What does the 0 in parantheses do?

unsigned long num (0);

Upvotes: 1

Views: 93

Answers (3)

Pandrei
Pandrei

Reputation: 4961

There are several types of variable initialization in C++:

  1. C-like initialization type identifier = initial_value; — example: int x = 0;
  2. Constructor initialization type identifier (initial_value); — example int x (0);
  3. Uniform initialization type identifier {initial_value}; — example int x {0};

Your example is for the second initialization type.

Upvotes: 3

Kiril Kirov
Kiril Kirov

Reputation: 38193

Initializes the variable num with 0.

It's also a definition, not only declaration in this case..

Upvotes: 5

Jonathan Leffler
Jonathan Leffler

Reputation: 755074

It initializes the variable to zero.

Upvotes: 3

Related Questions