C++ Data Types


Details of C++ Data Types

C++ offers multiple kinds of values that define what sort of content a variable can contain. These types help the system understand memory allocation and the behavior of operations performed on them. Each variety is chosen based on the purpose and form of data.


Categories of Data Kinds

  • Whole Number Holder: Stores digits without decimal parts. (int)
  • Floating Precision Form: Keeps numbers with fractions. (float, double)
  • Single Character Container: Holds one letter, symbol, or number. (char)
  • Truth Indicator: Handles only two choices — valid or invalid. (bool)
  • Extended Whole Format: Accommodates much bigger numeral ranges. (long, long long)

Example

#include <iostream>  // Access display functions  

int main() {     
     int age = 25;               // Numeric value     
     float height = 5.9;         // Decimal-included number     
     char grade = 'A';           // One-letter data     
     bool passed = true;         // Logical outcome      

     std::cout << age << "\n";     
     std::cout << height << "\n";     
     std::cout << grade << "\n";     
     std::cout << passed << "\n";      

     return 0;                   // Exit point 
} 

Line-by-Line Clarification

  • int age = 25; declares a variable holding a count without a fraction.
  • float height = 5.9; defines a figure that includes decimal spacing.
  • char grade = 'A'; assigns a symbol enclosed within single quotation marks.
  • bool passed = true; sets a logical flag with either true or false meaning.
  • std::cout sequences project every result line onto the screen.

C++ Data Types Table

Type NamePurpose DescriptionExample Entry
intStores round-counted figures42
floatKeeps numerical content with decimal elements3.14
doubleHolds extended-precision floating-point digits99.87654321
charContains a solitary character symbol'Z'
boolManages binary conditionsfalse
longAccommodates broader whole number spans123456789L
unsignedUses only non-negative numeric expressions250U

Prefer Learning by Watching?

Watch these YouTube tutorials to understand C++ Tutorial visually:

What You'll Learn:
  • 📌 Lec 10: DataTypes with Type Modifiers in C++ - part 1| int Data Type | C++ Tutorials for Beginners
  • 📌 Lec 11: Data Types in C++ - part 2 | float Data Type | C++ Tutorials for Beginners
Previous Next