Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C++ Course

Lesson 34 of 45 · C++

Lesson 4: Variables and Data Types

Duration: 9 min

Variables and Data Types\n\nVariables are named storage locations whose type determines the kind of data they can hold. C++ provides a rich set of built‑in types:\n- Integral – bool, char, signed/unsigned int, short, long, long long.\n- Floating‑point – float, double, long double.\n- Character – char (signed or unsigned depending on implementation) and char16_t, char32_t, wchar_t.\n- Boolean – bool with literals true and false.\n\nC++ also offers type inference via auto and type traits through <type_traits>.\n\n---\n\n## Example: Declaring and Initialising\ncpp\nint i = 42; // explicit type\nauto f = 3.14; // deduced as double\nunsigned long long big = 1ULL; // suffix U for unsigned, LL for long long\nbool flag = true; // boolean literal\n\n\nUse sizeof to query the byte size of a type:\ncpp\nstd::cout << \"Size of int: \" << sizeof(int) << \" bytes\\n\";\n\n\n> Tip: Prefer uniform initialisation (int x{5};) to avoid narrowing conversions.\n\n---\n\n<Alert type="info">auto does not mean dynamic typing; the type is still fixed at compile time.

Previous: Lesson 39: Mutexes and Locks (std::mutex, std::lock_guard)Next: Lesson 40: Atomic Operations (std::atomic)