C Language Reference

Pointers

int x = 42; int *p = &x; /* pointer to x */ *p = 100; /* dereference โ€” x is now 100 */ /* Pointer arithmetic */ int arr[5] = {1,2,3,4,5}; int *q = arr; printf("%d\n", *(q+2)); /* 3 */ /* Pointer to pointer */ int **pp = &p; printf("%d\n", **pp); /* 100 */

Memory Management

#include <stdlib.h> /* malloc โ€” uninitialized */ int *arr = malloc(10 * sizeof(int)); if (!arr) { /* always check! */ exit(1); } /* calloc โ€” zero-initialized */ int *arr2 = calloc(10, sizeof(int)); /* realloc */ arr = realloc(arr, 20 * sizeof(int)); /* Always free to avoid leaks */ free(arr); arr = NULL; /* prevent dangling pointer */

Structs

typedef struct { char name[64]; int age; float score; } Student; Student s = {"Alice", 20, 95.5f}; printf("%s: %d, %.1f\n", s.name, s.age, s.score); /* Pointer to struct */ Student *ps = &s; printf("%s\n", ps->name); /* arrow operator */

Standard Library

HeaderKey Functions
stdio.hprintf, scanf, fopen, fclose, fread, fwrite
stdlib.hmalloc, free, exit, atoi, qsort, bsearch
string.hstrlen, strcpy, strcat, strcmp, memcpy, memset
math.hsqrt, pow, abs, floor, ceil, sin, cos
time.htime, clock, difftime, strftime