DEV Community

Mayank Roy
Mayank Roy

Posted on

Day 4: Diving into Data Types – Building Blocks of C++

Importance of Data Types

  • C++ treats different data types, such as numbers and strings, distinctly.

  • The precision of numbers is crucial; for example, the distinction between 4 and 4.0 is significant in programming.

  • Charts can be used to show data types and their sizes, although memorizing them is not necessary for practical coding.

Types of Data Types

Image description

Primitive Data Types in C++

Primitive data types are the most basic types of data supported directly by the C++ language. They represent simple values such as numbers, characters, and logical states. Here’s a breakdown of the most common primitive data types:

Integer (int):

Stores whole numbers (no decimals).
Example: int age = 25;

Float (float):

Stores numbers with decimals (single precision).
Example: float temperature = 36.5;

Double (double):

Similar to float but stores more precise decimal numbers.
Example: double pi = 3.14159;

Character (char):

Stores a single character (letters, numbers, or symbols).
Example: char grade = 'A';

Boolean (bool):

Stores logical values: true or false.
Example: bool isPassed = true;

Void (void):

Represents "no data." Commonly used for functions that don’t return a value.

Top comments (0)