Resolving Shadowed Variables using this->

Medium Encapsulation, Access Specifiers & The this Pointer
Solve in Playground →

Problem Statement

Create a `Student` class with a private attribute `int id`. Write a constructor `Student(int id)` where the parameter name exactly matches the attribute name. Use `this->id = id;` to resolve the shadowing. Add a getter and print the ID in `main()`.

Input Format

A single integer.

Output Format

Print 'ID: [val]'.

Constraints

None

Sample Input

10

Sample Output

ID: 10

Explanation

When local parameters have the exact same name as class attributes, the local variable 'shadows' the class variable. Using `this->` explicitly points to the class attribute.

Starter Code

#include <iostream>

class Student {
    // Define attributes, constructor, and getter
};

int main() {
    // Instantiate Student with input and print
    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