Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

C++ Data Types and Keywords

Fundamental Data Types

TypeSizeRangeUse
bool1 bytetrue / falseBoolean logic
char1 byte-128 to 127Single character / ASCII
int4 bytes-2,147,483,648 to 2,147,483,647Whole numbers
long4"8 bytesplatform-dependentLarge integers
long long8 bytes+/-9.2 x 10^18Very large integers
float4 bytes~+/-3.4 x 10^38 (6-7 digits)Single-precision decimal
double8 bytes~+/-1.7 x 10^308 (15-16 digits)Double-precision decimal
long double8"16 bytesextended precisionHigh-precision decimal
void--No value (function return)
wchar_t2"4 byteswide charactersUnicode characters

Type Modifiers

Modifiers adjust the range or sign of a base type:

Modified TypeSizeRange
unsigned int4 bytes0 to 4,294,967,295
unsigned char1 byte0 to 255
unsigned long long8 bytes0 to 18.4 x 10^18
short int2 bytes-32,768 to 32,767
Data Types - sizeof and limits
#include <iostream>
#include <climits>   // INT_MAX, CHAR_MAX, etc.
#include <cfloat>    // FLT_MAX, DBL_MAX
using namespace std;

int main() {
    cout << "--- Sizes ---" << endl;
    cout << "bool:        " << sizeof(bool)        << " byte"  << endl;
    cout << "char:        " << sizeof(char)        << " byte"  << endl;
    cout << "int:         " << sizeof(int)         << " bytes" << endl;
    cout << "long long:   " << sizeof(long long)   << " bytes" << endl;
    cout << "float:       " << sizeof(float)       << " bytes" << endl;
    cout << "double:      " << sizeof(double)      << " bytes" << endl;

    cout << "\n--- Limits ---" << endl;
    cout << "INT_MAX:     " << INT_MAX     << endl;
    cout << "INT_MIN:     " << INT_MIN     << endl;
    cout << "CHAR_MAX:    " << (int)CHAR_MAX << endl;
    cout << "DBL_MAX:     " << DBL_MAX     << endl;

    // C++11 fixed-width types (preferred in portable code)
    #include <cstdint>
    // int8_t, int16_t, int32_t, int64_t
    // uint8_t, uint16_t, uint32_t, uint64_t

    return 0;
}

C++ Keywords

Keywords are reserved words with special meaning. You cannot use them as variable names.

CategoryKeywords
Typesint, float, double, char, bool, void, auto, long, short, unsigned, signed
Control flowif, else, switch, case, default, for, while, do, break, continue, return, goto
OOPclass, struct, public, private, protected, virtual, override, final, this, new, delete
Memorynew, delete, sizeof, nullptr
Templatestemplate, typename, concept, requires
Exceptionstry, catch, throw, noexcept
Modifiersconst, constexpr, static, extern, inline, volatile, mutable, explicit
Namespacesnamespace, using
Othertrue, false, nullptr, operator, friend, typedef, enum, union
Type Casting in C++
#include <iostream>
using namespace std;

int main() {
    // Implicit conversion (promotion)
    int   i = 5;
    double d = i;   // int â†' double automatically
    cout << d << endl;  // 5.0

    // C-style cast (avoid in C++)
    double pi = 3.14159;
    int truncated = (int)pi;  // 3

    // C++ static_cast (preferred)
    int a = 7, b = 2;
    double result = static_cast<double>(a) / b;  // 3.5
    cout << "7/2 = " << result << endl;

    // static_cast for char â†" int
    char ch = 'A';
    int ascii = static_cast<int>(ch);
    cout << "'A' = " << ascii << endl;  // 65

    return 0;
}

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.