Swap Two Numbers

Medium Pointer Fundamentals
Solve in Playground →

Problem Statement

Write a C program to swap two numbers using pointers and a helper function (or direct pointer manipulation).

Input Format

Two space-separated integers.

Output Format

Print the swapped integers separated by a space.

Constraints

Standard integer limits

Sample Input

5 10

Sample Output

10 5

Explanation

Pass pointers to two variables into a function and use a temporary variable to swap values at their addresses.

Starter Code

#include <stdio.h>

void swap(int *a, int *b) {
    // Write your swap logic here
}

int main() {
    int x, y;
    if (scanf("%d %d", &x, &y) == 2) {
        swap(&x, &y);
        printf("%d %dn", x, y);
    }
    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