C Snippets

A collection of useful code snippets for C Programming.

Hello World

C-programming
hello
hello-world.c
#include <stdio.h>

int main() {
    printf("Hello, World!");
    return 0;
}

Pointer Example

C-programming
pointer
pointer-example.c
#include <stdio.h>

int main() {
    int myAge = 43;      // An int variable
    int* ptr = &myAge;   // A pointer variable, with the name ptr, that stores the address of myAge

    // Output the value of myAge (43)
    printf("%d\n", myAge);

    // Output the memory address of myAge
    printf("%p\n", &myAge);

    // Output the memory address of myAge with the pointer
    printf("%p\n", ptr);

    return 0;
}