HOME HTML EDITOR C JAVA PHP

C Quick Reference:

The C Reference provides a bird's-eye view of the most important syntax, data types, and library functions. Use this as a guide for quick lookup when writing or debugging code.

1. Data Types and Sizes

While sizes vary by architecture, these are the standard sizes for modern 64-bit systems:

Type Size Format Specifier
char 1 Byte %c
int 4 Bytes %d
float 4 Bytes %f
double 8 Bytes %lf

2. Control Flow Syntax

Standard structures for decision making and loops:

// If-Else
if (condition) { ... } else if (cond2) { ... } else { ... }

// Switch Case
switch(var) {
    case 1: ... break;
    default: ...
}

// Loops
for (int i=0; i < n; i++) { ... }
while (condition) { ... }
do { ... } while (condition);

3. Pointer Reference

Pointers are variables that store memory addresses. They are the most powerful and dangerous part of C.

4. Common Library Functions

Standard functions found in <stdio.h>, <stdlib.h>, and <string.h>:

Function Purpose
printf() / scanf() Output to screen / Input from keyboard.
malloc() / free() Allocate / Deallocate memory on the heap.
strlen() Find the length of a string (excluding \0).
fopen() / fclose() Open and close a file stream.

5. Escape Sequences

Special characters used inside strings:

6. Operator Precedence

The order in which operators are evaluated (Top = Highest):

  1. Parentheses: (), [], ->
  2. Unary: ++, --, !, *, &
  3. Arithmetic: *, /, % then +, -
  4. Relational: <, >, ==, !=
  5. Logical: && then ||
  6. Assignment: =, +=, *= etc.
Pro Tip: When in doubt about precedence, use parentheses (). It makes your code clearer and prevents subtle bugs that are hard to find!