C Programming Cheat Sheet β Complete Syntax, Data Types, Functions, and Examples
π Key Takeaways
- C Programming Cheat Sheet β Complete Syntax, Data Types, Functions, and Examples
- C Programming Language Cheat Sheet
- C Language Basics
- Data Types in C
- C Variables and Constants
- Operators in C
Table of Contents:
Advertisement
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