AI Generate C docs instantly

C Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

2 snippets

Basic C program structure

Hello World

#include <stdio.h>

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

Comments

// Single line comment
/* Multi-line
   comment */

Variables & Types

5 snippets

Data types and declarations

Integer

int age = 25;
long count = 1000000;
short num = 32000;

Float & Double

float price = 19.99f;
double pi = 3.14159265359;

Char

char letter = 'A';
char name[] = "John";

Constants

const int MAX = 100;
#define PI 3.14159

Type Casting

int x = 10;
float y = (float)x;
int z = (int)3.14;

Operators

4 snippets

Arithmetic and logic

Arithmetic

int a = 5 + 3;  // 8
int b = 5 - 3;  // 2
int c = 5 * 3;  // 15
int d = 5 / 3;  // 1
int e = 5 % 3;  // 2

Comparison

5 == 5  // 1 (true)
5 != 3  // 1 (true)
5 > 3   // 1 (true)
5 < 3   // 0 (false)

Logical

(5 > 3) && (2 < 4)  // 1 (true)
(5 > 3) || (2 > 4)  // 1 (true)
!(5 > 3)             // 0 (false)

Increment/Decrement

int x = 5;
x++;  // 6 (post-increment)
++x;  // 7 (pre-increment)
x--;  // 6 (post-decrement)
--x;  // 5 (pre-decrement)

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Control Flow

5 snippets

Conditionals and loops

If/Else

if (x > 0) {
    printf("positive");
} else if (x < 0) {
    printf("negative");
} else {
    printf("zero");
}

Switch

switch (day) {
    case 1:
        printf("Monday");
        break;
    case 2:
        printf("Tuesday");
        break;
    default:
        printf("Other");
}

For Loop

for (int i = 0; i < 10; i++) {
    printf("%d\n", i);
}

While Loop

int i = 0;
while (i < 10) {
    printf("%d\n", i);
    i++;
}

Do-While

int i = 0;
do {
    printf("%d\n", i);
    i++;
} while (i < 10);

Arrays

4 snippets

Fixed-size collections

Declaration

int numbers[5];
int nums[] = {1, 2, 3, 4, 5};

Access

int first = nums[0];
nums[1] = 10;

2D Array

int matrix[3][3] = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

String

char name[] = "John";
char greeting[20] = "Hello";

Functions

3 snippets

Reusable code blocks

Function

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

int result = add(5, 3);  // 8

Void Function

void greet() {
    printf("Hello!\n");
}

Function Prototype

// Declare before use
int multiply(int a, int b);

int main() {
    int result = multiply(3, 4);
    return 0;
}

int multiply(int a, int b) {
    return a * b;
}

Pointers

4 snippets

Memory addresses and references

Pointer Declaration

int x = 10;
int *ptr = &x;  // ptr stores address of x

Dereference

int value = *ptr;  // Get value at address
*ptr = 20;         // Modify value

Null Pointer

int *ptr = NULL;

Pointer Arithmetic

int arr[] = {1, 2, 3};
int *p = arr;
p++;  // Move to next element

Structs

4 snippets

Custom data types

Define Struct

struct Person {
    char name[50];
    int age;
    float height;
};

Create & Use

struct Person person1;
strcpy(person1.name, "John");
person1.age = 30;

Initialize

struct Person person2 = {
    "Jane",
    25,
    5.6
};

Typedef

typedef struct {
    char name[50];
    int age;
} Person;

Person p;  // No 'struct' needed

More Cheat Sheets

FAQ

Frequently asked questions

What is a C cheat sheet?

A C cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in C. It helps developers quickly look up syntax without searching through documentation.

How do I learn C quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important C concepts?

Key C concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my C code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your C code using AI.

Code Conversion Tools

Convert C to Other Languages

Easily translate your C code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate C Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week