100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

C Cheat Sheet

C Cheat Sheet

Fundamental C syntax including pointers, arrays, structs, memory allocation, and standard library functions for systems programming.

2 PagesBeginnerApr 10, 2026

Basic Syntax

Variables, control flow, and I/O.

c
#include <stdio.h>int main(void) {    int age = 30;    double pi = 3.14159;    char name[] = "Ada";    if (age >= 18) {        printf("%s is an adult\n", name);    }    for (int i = 0; i < 5; i++) {        printf("Count: %d\n", i);    }    return 0;}

Pointers & Arrays

Direct memory access and array decay.

c
int x = 42;int *p = &x;        // p holds address of x*p = 100;            // dereference: x is now 100int arr[5] = {1, 2, 3, 4, 5};int *ptr = arr;      // array decays to pointerprintf("%d\n", *(ptr + 2));  // 3, same as arr[2]void swap(int *a, int *b) {    int temp = *a;    *a = *b;    *b = temp;}

Memory Management

Manual heap allocation with malloc/free.

c
#include <stdlib.h>int *arr = malloc(5 * sizeof(int));  // allocate on heapif (arr == NULL) {                   // always check for failure    return 1;}arr[0] = 10;arr = realloc(arr, 10 * sizeof(int)); // grow the blockfree(arr);                            // release memoryarr = NULL;                           // avoid dangling pointer

Standard Library Functions

Commonly used string.h and stdio.h functions.

  • strlen(s)- returns the length of a null-terminated string
  • strcpy(dst, src)- copies src into dst (unsafe if dst too small)
  • strcmp(a, b)- returns 0 if strings a and b are equal
  • memcpy(dst, src, n)- copies n bytes from src to dst
  • sizeof(x)- compile-time operator returning size in bytes
  • printf/scanf- formatted output/input with format specifiers like %d, %s, %f
  • fopen/fclose- open and close file streams
Pro Tip

Always check the return value of malloc/calloc/realloc for NULL, and set freed pointers to NULL to avoid dangling-pointer bugs.

Was this cheat sheet helpful?

Explore Topics

#CCheatSheet#Programming#Beginner#BasicSyntax#PointersArrays#MemoryManagement#StandardLibraryFunctions#Functions#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet