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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Lesson 4: Variables and Data Types | C++ Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. C++ Course

Lesson 4 of 45

·C++

Lesson 4: Variables and Data Types

9 min

Course progress9%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Primitive types (int, double, char, bool)
  • Type inference with auto
  • Signed vs. unsigned
  • Scope and lifetime

Variables and Data Types

Variables are named storage locations whose type determines the kind of data they can hold. C++ provides a rich set of built‑in types:

  • Integral – bool, char, signed/unsigned int, short, long, long long.
  • Floating‑point – float, double, long double.
  • Character – char (signed or unsigned depending on implementation) and char16_t, char32_t, wchar_t.
  • Boolean – bool with literals true and false.

C++ also offers type inference via auto and type traits through <type_traits>.


Example: Declaring and Initialising

int        i = 42;               // explicit type
auto       f = 3.14;            // deduced as double
unsigned long long big = 1ULL; // suffix U for unsigned, LL for long long
bool       flag = true;        // boolean literal

Use sizeof to query the byte size of a type:

std::cout << \"Size of int: \" << sizeof(int) << \" bytes\
\";

Tip: Prefer uniform initialisation (int x{5};) to avoid narrowing conversions.


<Alert type="info">auto does not mean dynamic typing; the type is still fixed at compile time.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from C++ CourseBrowse activities
Previous lessonLesson 3: Hello World and Basic SyntaxContinue to lesson 5Lesson 5: OperatorsBack to C++ Course curriculum