C++ Decimals and Integers

How do we represent integer data ? What are integers ?

Integers are just like whole numbers, but they also include negative numbers

int data type

  • stores decimals
  • typically occupies 4 bytes or more in memory

Braced Initialization – {}

For that last example, braced variable initialization throws narrowing conversion compiler error.

Functional variable initialization

Works almost like braced initialization, but less safer than braced initialization.

For that last example, functional variable initialization assigns value 2 to the variable.

Assignment initialization

For the last example, assignment variable initialization does narrowing of variable and assigns value 2 to the variable.

Size of a type in memory

using sizeof operator.

int – generally takes 4 bytes of memory.