Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 10 of 10

Practice & Quiz - C++ Fundamentals

Consolidate your understanding of the C++ compilation pipeline, primitive types, namespaces, constexpr, and CMake with a practical exercise and 5 quiz questions.

10 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Practical Exercise - Explore Your System's Type Sizes

Practical Exercise - Explore Your System's Type Sizes
#include <iostream>
#include <cstdint>
#include <limits>

// Practical: run this and compare sizes across platforms
int main() {
    // Guaranteed-width types - always prefer for portable code
    std::cout << "int8_t   : " << sizeof(int8_t)   << " byte\n";
    std::cout << "int32_t  : " << sizeof(int32_t)  << " bytes\n";
    std::cout << "int64_t  : " << sizeof(int64_t)  << " bytes\n";
    std::cout << "uint64_t : " << sizeof(uint64_t) << " bytes\n";

    // Platform-dependent sizes
    std::cout << "\nPlatform sizes:\n";
    std::cout << "int    : " << sizeof(int)    << "\n";
    std::cout << "long   : " << sizeof(long)   << "\n";
    std::cout << "void*  : " << sizeof(void*)  << "\n";

    // auto deduction demo
    auto a = 42;          // int
    auto b = 42.0;        // double
    auto c = 42.0f;       // float
    auto d = "hello";     // const char* - NOT std::string!
    std::cout << "\nsizeof auto-deduced:\n";
    std::cout << "auto 42    : " << sizeof(a) << "\n";  // 4
    std::cout << "auto 42.0  : " << sizeof(b) << "\n";  // 8
    std::cout << "auto 42.0f : " << sizeof(c) << "\n";  // 4

    // constexpr - compile-time factorial
    constexpr int factorial(int n);  // forward decl
    // constexpr int f5 = factorial(5);  // 120 at compile time

    // Numeric limits
    std::cout << "\nINT_MAX  = " << std::numeric_limits<int>::max()    << "\n";
    std::cout << "DBL_MAX  = " << std::numeric_limits<double>::max() << "\n";

    return 0;
}
// Build: g++ -Wall -std=c++17 types_demo.cpp -o types_demo && ./types_demo

Module Quiz

Module Quiz
Question 1 of 5

What does `g++ -std=c++17 -c main.cpp -o main.o` produce?

Tip

Tip

Practice Practice Quiz C Fundamentals in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Core Foundations: Architecture, Types, Operators, Namespaces, Constants & Multi-File Builds

Practice Task

Note

Practice Task - (1) Write a working example of Practice Quiz C Fundamentals from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Common Mistake

Warning

A common mistake with Practice Quiz C Fundamentals is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cpp code.

Topics in This Module

0/10 done