YouTip LogoYouTip

C Functions and Structures

Functions

int add(int a, int b) {
    return a + b;
}

void greet(char name[]) {
    printf("Hello, %s!\n", name);
}

Structures

struct Point {
    int x;
    int y;
};

struct Point p = {10, 20};
printf("%d, %d", p.x, p.y);

Memory Management

#include <stdlib.h>
int *arr = malloc(5 * sizeof(int));
free(arr);

Summary

  • malloc/free for dynamic memory
  • Structs group related data
← C++ Tutorial - Getting StartedC Pointers and Arrays β†’