Table of Contents:
C Programming Language Cheat Sheet — Complete Guide for Beginners and Professionals
The C programming language is one of the most powerful, efficient, and widely used programming languages in the world. It forms the foundation for modern languages like C++, Java, and Python.
This C Cheat Sheet provides a quick reference for all important syntax, commands, and structures in C language programming — from variables to pointers, with practical examples.
C Language Basics
| Concept | Description | Example |
|---|---|---|
| File Extension | .c | main.c |
| Compiler | Used to compile code (e.g., GCC, Turbo C) | gcc main.c -o main |
| Execution | Run the compiled program | ./main |
| Comment | Adds code explanations | // single line or /* multi-line */ |
Example:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
Data Types in C
| Type | Keyword | Size (bytes) | Range (approx.) |
|---|---|---|---|
| Integer | int | 2 or 4 | -32,768 to 32,767 |
| Character | char | 1 | -128 to 127 |
| Float | float | 4 | 3.4E-38 to 3.4E+38 |
| Double | double | 8 | 1.7E-308 to 1.7E+308 |
| Void | void | 0 | N/A |
Example:
int age = 25;
float height = 5.9;
char grade = 'A';
C Variables and Constants
| Type | Syntax Example | Explanation |
|---|---|---|
| Variable | int num = 10; | Stores integer value |
| Constant | const float PI = 3.14; | Value cannot be changed |
| Global Variable | Declared outside all functions | Accessible throughout program |
Operators in C
| Type | Operators | Example |
|---|---|---|
| Arithmetic | + - * / % | a + b |
| Relational | == != > < >= <= | if (a > b) |
| Logical | `&& | |
| Assignment | = += -= *= /= | x += 10 |
| Increment/Decrement | ++ -- | i++ |
| Bitwise | `& | ^ ~ << >>` |
| Ternary | ? : | result = (a > b) ? a : b; |
Control Statements in C
| Statement | Syntax | Description |
|---|---|---|
| if | if (condition) { } | Executes if condition is true |
| if-else | if (condition) else | Executes one of two blocks |
| switch | switch(expression) | Executes based on multiple cases |
| break | break; | Exits from a loop or switch |
| continue | continue; | Skips current iteration |
Example:
if (age >= 18)
printf("Eligible to vote");
else
printf("Not eligible");

Loops in C
| Loop Type | Syntax | Usage |
|---|---|---|
| for loop | for(init; condition; inc) | Repeats known number of times |
| while loop | while(condition) | Repeats while condition is true |
| do-while loop | do { } while(condition); | Executes at least once |
Example:
for(int i=1; i<=5; i++)
printf("%d ", i);
Functions in C
| Type | Syntax Example | Description |
|---|---|---|
| Built-in | printf(), scanf() | Provided by C library |
| User-defined | void greet() { } | Created by programmer |
| Function with return | int sum(int a, int b) | Returns value |
Example:
int add(int a, int b) {
return a + b;
}
Arrays in C
| Type | Syntax Example | Usage |
|---|---|---|
| One-dimensional | int arr[5]; | Store multiple values |
| Two-dimensional | int matrix[3][3]; | For tables or grids |
Example:
int nums[3] = {10, 20, 30};
printf("%d", nums[1]); // Output: 20
Pointers in C
Pointers store memory addresses of variables.
Syntax:
int num = 10;
int *ptr = #
printf("%d", *ptr); // Output: 10
| Symbol | Meaning |
|---|---|
& | Address-of operator |
* | Value-at-address operator |
Strings in C
Strings are arrays of characters ending with a null character \0.
Example:
char name[20] = "C Language";
printf("Welcome to %s", name);
| Function | Usage |
|---|---|
strlen(str) | Find string length |
strcpy(dest, src) | Copy string |
strcmp(s1, s2) | Compare strings |
strcat(s1, s2) | Concatenate strings |
c programming cheat sheet, c language reference, c syntax examples, c programming basics, c data types table, c functions examples, c pointers tutorial, c arrays cheat sheet, c file handling examples, c programming pdf
File Handling in C
| Mode | Meaning |
|---|---|
"r" | Read mode |
"w" | Write mode |
"a" | Append mode |
"r+" | Read + Write |
"w+" | Write + Read |
Example:
FILE *fp = fopen("data.txt", "w");
fprintf(fp, "Hello C!");
fclose(fp);
FAQ — C Programming Language
Q1: Why is C still important in 2025?
C is the foundation of most modern languages and operating systems, including Linux and embedded systems.
Q2: How do I run a C program online?
Use online compilers like phponline.in C Editor or GCC locally.
Q3: What is the difference between C and C++?
C++ extends C by adding object-oriented programming (classes, inheritance, polymorphism).
Q4: What are the best IDEs for C programming?
Code::Blocks, Visual Studio Code, and Eclipse CDT are great options.
Q5: How do I learn C quickly?
Practice small projects like calculators, pattern printing, and file I/O programs.

