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
  • 12,499
  • 17
  • 70
  • 145

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
  • 43,322
  • 6
  • 62
  • 109
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
  • 58,324
  • 8
  • 149
  • 196