C++ Data Types

Primitive Data Types

These are the most commonly used built-in types:

  • int: whole numbers
  • float, double: decimal numbers
  • char: single character (enclosed in single quotes)
  • bool: true or false
int age = 25;
float price = 19.95;
char grade = 'A';
bool isPassed = true;

Type Modifiers

Modifiers adjust size or behavior:

  • short, long, long long
  • unsigned → positive values only
unsigned int u = 42;
long long big = 900000000000LL;

Strings

Use the string type for text (requires #include <string>):

string name = "Alice";

Size of Types

Use sizeof() to check how much memory a type uses:

cout << sizeof(int);       // 4 (typically)
cout << sizeof(double);    // 8

Type Conversion

C++ supports implicit and explicit type conversions:

int a = 10;
double b = a;        // implicit
int c = (int)b;      // explicit cast

Auto Keyword

auto lets the compiler deduce the type:

auto score = 95;       // int
auto name = "Bob";   // const char*

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic