Memory Footprint of an Object (sizeof)

Medium Introduction to C++ Classes & Objects
Solve in Playground →

Problem Statement

Define an empty class `Empty` and a class `Data` containing two `int` attributes. In `main()`, use the `sizeof()` operator to print their memory footprints on separate lines.

Input Format

None

Output Format

Print 'Empty: [size]' and 'Data: [size]'.

Constraints

Assuming a standard 64-bit architecture where int is 4 bytes.

Sample Output

Empty: 1
Data: 8

Explanation

An empty class takes 1 byte to ensure unique memory addresses, whereas a class with two integers allocates exactly the required payload size (4 + 4 = 8 bytes).

Starter Code

#include <iostream>

// Define Empty and Data classes here

int main() {
    // Print their sizes
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used