Skip to content

Instantly share code, notes, and snippets.

@smarteist
Created May 28, 2025 06:58
Show Gist options
  • Save smarteist/66c74bf003da35d306f20e8ca5a995e6 to your computer and use it in GitHub Desktop.
Save smarteist/66c74bf003da35d306f20e8ca5a995e6 to your computer and use it in GitHub Desktop.

Revisions

  1. smarteist created this gist May 28, 2025.
    23 changes: 23 additions & 0 deletions main.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #include <stdio.h>

    int main() {
    // 1. Declaring a Pointer
    int *ptr; // Pointer to an integer

    // 2. Assigning Address to a Pointer
    int var = 10;
    ptr = &var; // ptr now holds the address of var

    // 3. Dereferencing a Pointer
    int value = *ptr; // value is now 10 (the value of var)

    // 4. Modifying Value via Pointer
    *ptr = 20; // var is now 20

    // Example Output
    printf("Value of var: %d\n", var); // Output: 20
    printf("Address of var: %p\n", (void*)&var); // Output: Address of var
    printf("Value via pointer: %d\n", *ptr); // Output: 20

    return 0;
    }