Reference vs Pointer

Medium References
Solve in Playground →

Problem Statement

Write a C++ program demonstrating that a reference cannot be reseated after initialization, unlike a pointer.

Input Format

Two space-separated integers A and B.

Output Format

Print reference value before and after attempting reassignment to show original variable holds updated alias target.

Constraints

-10000 <= A, B <= 10000

Sample Input

10 20

Sample Output

Initial: 10
After Reassignment Assignment: 20

Explanation

References remain bound to their initial target throughout their lifetime.

Starter Code

#include <iostream>

int main() {
    int a, b;
    if (std::cin >> a >> b) {
        int &ref = a;
        std::cout << "Initial: " << ref << "n";
        ref = b; // Assigns value to a, doesn't reseat reference
        std::cout << "After Reassignment Assignment: " << a << "n";
    }
    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