Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Data Types | Variables and Data Types
C++ Introduction
course content

Course Content

C++ Introduction

C++ Introduction

1. Getting Started
2. Introduction to Operators
3. Variables and Data Types
4. Introduction to Program Flow
5. Introduction to Functions

bookData Types

When declaring a variable, you need to specify what type of data we will store in it. There are data types for easy memory handling for every situation.

Integer Types
int
short
Floating Point Types
float
double
Character Types
char
string
Other Types
bool
void

Numerical

These types are essential for storing numerical values and performing mathematical operations. They are divided into two main groups: integer types, which store whole numbers, and floating-point types, which store numbers with fractional parts.

h

integers

h

decimals

copy
12
// examples of literal integers 5 100 30

Bool

The bool data type represents two boolean values: zero interpreted as false and one is interpreted as true.

on = true = 1
off = false = 0

Char

The char data type is used to store individual characters, which can include letters, digits, punctuation marks, and special characters. These characters must be enclosed in single quotes ('), such as 'A', '9', or '!'.

Void

The void data type represents the absence of a value. It is primarily used for functions that do not return any data. When a function is declared as void, it means the function performs an action but does not provide a result.

Note

The use and purpose of void will be explored further in the chapter about functions.

You can check the data type of certain expressions using the code below. Feel free to experiment with it.

cpp

main

copy
123456789
#include <iostream> #include <typeinfo> // Provides tools for type identification int main() { // `typeid().name()` gives you the type of expression // Replace `___` with a number, boolean (true/false), or character std::cout << "The data type is " << typeid(___).name() << std::endl; }
1. What does the int data type store?
2. What is the correct syntax for a `char` type?
What does the int data type store?

What does the int data type store?

Select the correct answer

What is the correct syntax for a `char` type?

What is the correct syntax for a char type?

Select a few correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 1
We're sorry to hear that something went wrong. What happened?
some-alt