summaryrefslogtreecommitdiff
path: root/main.c
blob: 30d5c6195d71cfe0c0af4564faab5fd232f92d6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>

// Function that tries to change a number without pointer
void noPointerChange(int num) {
    num = 100;  // Changes local copy only
}

// Function that changes a number using pointer
void pointerChange(int *numPtr) {
    *numPtr = 100;  // Changes original value through pointer
}

int main() {
    int value = 50;

    printf("Before noPointerChange: %d\n", value);
    noPointerChange(value);
    printf("After noPointerChange: %d\n", value);  // value unchanged

    printf("Before pointerChange: %d\n", value);
    pointerChange(&value);
    printf("After pointerChange: %d\n", value);    // value changed

    return 0;
}