0

what is bool(), int(), and double() in c++/c++11? Are they true, 0 and 0.0 in c++ or c++11 standard?

user1899020
  • 13,167
  • 21
  • 79
  • 154

2 Answers2

3

T() ia a value-initialized prvalue of type T since C++03 when value-initialization was introduced.

It is false for bool, 0 for arithmetic and nullptr for pointer-types.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
3

Quoting the C++11 FD, [expr.type.conv]/2:

The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified) void type, creates a prvalue of the specified type, whose value is that produced by value-initializing (8.5) an object of type T; no initialization is done for the void() case.

And value-initialization implies zero-initialization for scalars.

Columbo
  • 60,038
  • 8
  • 155
  • 203