Cambo Freelance
ទំព័រដើមសេវាកម្មអត្ថបទការបង្រៀនក្រុមវគ្គបណ្តុះបណ្តាលទំនាក់ទំនង
Cambo Freelance

Professional freelance team from Cambodia delivering technology-driven solutions with cultural insight and modern expertise.

ផ្ញើសាររបស់អ្នក

ត្រៀមចាប់ផ្តើមគម្រោងរបស់អ្នក? ទំនាក់ទំនងក្រុមរបស់យើង។

ទំនាក់ទំនង

សេវាកម្ម

  • Web & Mobile Development Services
  • Graphic Design & Branding Services

តំណភ្ជាប់មានប្រយោជន៍

  • ទំព័រដើម
  • សេវាកម្ម
  • ការសិក្សា
  • អំពីយើង
  • ទំនាក់ទំនង
  • តម្លៃ

© 2026 Cambo Freelance. រក្សាសិទ្ធិទាំងអស់។

TelegramFacebookLinkedInEmail
HomeTutorialsC++C++ Data Types
⚡C++ Tutorials

50 lessons

Beginner(21)1C++ Introduction2C++ Getting Started3C++ Syntax4C++ Output5C++ Comments6C++ Variables7C++ Data Types8C++ Constants9C++ User Input10C++ Operators11C++ Strings12C++ Math13C++ Booleans14C++ Conditions15C++ Switch16C++ Loops17C++ Break and Continue18C++ Arrays19C++ Functions20C++ References21C++ Pointers
Intermediate(19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers
Advanced(10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44
⚡

C++ Tutorials

Lesson 7 of 50

All lessons
Beginner (21)1C++ Introduction2C++ Getting Started
26
C++ Encapsulation
27C++ Inheritance
28C++ Polymorphism
29C++ Abstraction
30C++ Files
31C++ Exception Handling
32C++ Namespaces
33C++ Structures
34C++ Enumerations
35C++ STL Introduction
36C++ Vectors
37C++ Maps
38C++ Sets
39C++ Queues
40C++ Stacks
C++ Move Semantics
45C++ Multithreading
46C++ Design Patterns
47C++ Memory Management
48C++17 Features
49C++20 Features
50C++ Performance Optimization
3
C++ Syntax
4C++ Output
5C++ Comments
6C++ Variables
7C++ Data Types
8C++ Constants
9C++ User Input
10C++ Operators
11C++ Strings
12C++ Math
13C++ Booleans
14C++ Conditions
15C++ Switch
16C++ Loops
17C++ Break and Continue
18C++ Arrays
19C++ Functions
20C++ References
21C++ Pointers
Intermediate (19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers26C++ Encapsulation27C++ Inheritance28C++ Polymorphism29C++ Abstraction30C++ Files31C++ Exception Handling32C++ Namespaces33C++ Structures34C++ Enumerations35C++ STL Introduction36C++ Vectors37C++ Maps38C++ Sets39C++ Queues40C++ Stacks
Advanced (10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44C++ Move Semantics45C++ Multithreading46C++ Design Patterns47C++ Memory Management48C++17 Features49C++20 Features50C++ Performance Optimization
⚡C++BeginnerLesson 7 of 50CamboFreelanceJune 19, 2026

C++ Data Types

Explore all C++ data types including integers, floats, chars, and booleans. Learn sizes, ranges, and how to avoid overflow.


Tutorials › C++ › Data Types
Beginner8 min readLesson 7 of 50

In This Lesson

  • Basic Types
  • Type Sizes
  • Overflow
  • Quiz

C++ Basic Data Types

C++ is a statically typed language, meaning every variable must have a declared type. The type determines what kind of data is stored and how much memory it uses.

Integer Types

TypeSizeRange
short2 bytes-32,768 to 32,767
int4 bytes-2,147,483,648 to 2,147,483,647
long4–8 bytesat least 32-bit range
long long8 bytes±9.2 × 10¹⁸

Floating-Point Types

TypeSizePrecision
float4 bytes~6–7 decimal digits
double8 bytes~15–16 decimal digits
long double8–16 byteseven higher precision
#include <iostream>
using namespace std;

int main() {
    int    a = 1000000;
    double b = 3.14159265358979;
    float  c = 3.14f;           // Use 'f' suffix for float literals
    char   d = 'Z';
    bool   e = false;

    cout << "int:    " << a << endl;
    cout << "double: " << b << endl;
    cout << "float:  " << c << endl;
    cout << "char:   " << d << endl;
    cout << "bool:   " << e << endl;
    return 0;
}

Output:

int:    1000000
double: 3.14159265358979
float:  3.14
char:   Z
bool:   0

Checking Type Sizes with sizeof

cout << "int size:    " << sizeof(int)    << " bytes" << endl;
cout << "double size: " << sizeof(double) << " bytes" << endl;
cout << "char size:   " << sizeof(char)   << " bytes" << endl;

Output:

int size:    4 bytes
double size: 8 bytes
char size:   1 bytes

Integer Overflow

If you store a value too large for its type, overflow occurs — the value wraps around unexpectedly:

short x = 32767;
x++;
cout << x;   // Output: -32768 (overflow!)
Warning: Always choose a data type large enough to hold the values you expect.

Exercise

Declare variables for: the population of Earth (use long long), the speed of light in m/s (use double), the first letter of the alphabet (use char). Print all three.

Show Solution
#include <iostream>
using namespace std;

int main() {
    long long earthPopulation = 8000000000LL;
    double speedOfLight = 299792458.0;
    char firstLetter = 'A';

    cout << "Population: " << earthPopulation << endl;
    cout << "Speed of Light: " << speedOfLight << endl;
    cout << "First Letter: " << firstLetter << endl;
    return 0;
}

Quiz

  1. Which type uses 8 bytes and stores high-precision decimals?

    • A) float
    • B) int
    • C) double
    • D) char
    Answer

    C) double — it uses 8 bytes and provides ~15 decimal digits of precision.

  2. What operator returns the size in bytes of a data type?

    • A) size()
    • B) sizeof
    • C) length()
    • D) bytes()
    Answer

    B) sizeof

Summary

  • C++ has several integer types: short, int, long, long long.
  • Floating-point types: float, double, long double.
  • sizeof(type) returns the number of bytes used.
  • Use long long for very large integers to avoid overflow.
← Previous: Variables Next: C++ Constants →
c++data-typesintdoublebeginner
PreviousLesson 6: C++ VariablesNextLesson 8: C++ Constants
Back to All Tutorials