C Language Cheat Sheet
C Language Cheat Sheet
🕰️ History of C + Keywords
● History: C was invented in the 1970s by Dennis Ritchie at Bell Labs. It helped create
early operating systems, especially UNIX. C is called the "mother of all languages"
ns
because many languages like C++, Java, and Python came from it.
● Keywords: These are special reserved words in C that you can’t use as variable
tio
names. Examples:
ui
○ return → ends a function
○ if → checks a condition
tT
● There are 32 keywords in C, and they all have a fixed meaning.
en
om
● Type Modifiers like short, long, unsigned change the size or range.
Example:
ns
○ +, -, *, /, % → basic math
tio
○ ==, !=, <, > → comparisons
ui
○ * and / happen before + and -
tT
● Associativity: Tells which side the operation starts from (usually left to right).
en
if (money > 0) {
La
buy_chocolate();
} else {
stay_home();
ns
● Loops let you repeat tasks:
tio
○ do-while → run once, then check
ui
○ for → best when you know how many times to repeat
Example:
tT
for (int i = 1; i <= 5; i++) {
en
printf("%d ", i); // prints 1 2 3 4 5
}
om
● Jump Statements:
🧩 Functions
La
Example:
return a + b;
This is a function called add that takes two numbers and gives back their sum.
ns
Types of Functions
✅ Built-in Functions:
tio
●
Already made by C.
Example: printf() to print on the screen.
ui
● 🧑💻 User-defined Functions: tT
You create these yourself to do a specific job.
en
●
A copy of the data is sent.
Original value stays safe.
🔗 Pass by Reference:
M
●
The actual variable is sent.
Changes will affect the original value too.
st
🔄 Recursion
La
● A function that calls itself. Like looking at a mirror that reflects another mirror!
● Used for repeating tasks like solving puzzles.
🏷️ Storage Classes
They tell:
Examples:
ns
● auto → default
tio
● extern → variable from another file
ui
🎯 Pointers tT
A pointer is a variable that stores the memory address of another variable.
en
int a = 10;
om
A+B : https://classplusapp.com/w/wlp/cjzgt/ccat-videos-section-a-and-b
A+B+C : https://classplusapp.com/w/wlp/cjzgt/ccat-videos-section-a-and-b-and-c
Arrays
An array is a group of similar items (like numbers) stored together.
An array is like a row of boxes 📦📦📦 that hold similar types of data — like only numbers,
or only letters.
ns
➡️ This is an array that holds 5 numbers.
Each number is kept in a separate box (position).
tio
Each box has a number in it, and you can access them using positions (called indexes).
● marks[0] is 10
ui
● marks[1] is 20 tT
…and so on.
en
It helps you store and manage many values easily.
om
● 3 4
La
Types of Arrays:
✅ Static Array:
Size is fixed from the beginning (before the program runs).
🔄 Dynamic Array:
Size is decided while the program is running, using malloc().
You can use pointers to access and move through the array.
(Eg: You can move from one box to the next using pointer math!)
ns
Strings
tio
A string is just a bunch of characters (letters) put together.
ui
Example:
● char names[5][10];
● char *names[5];
ns
You can also give input to your program using the terminal (command prompt).
Like this:
tio
./myprogram hello world
ui
Your program can read "hello" and "world" as strings!
tT
⚙️ Preprocessor Directives
en
● Macro vs Function:
La
🏗️ Structure
A structure is like a custom-made box that can hold different types of data together.
For example, if you want to store details of a student — like name (text), age (number), and
marks (decimal) — you can group them using a structure.
🧾 Example:
struct Student {
ns
char name[20];
int age;
tio
float marks;
ui
};
💡 In short:
st
La
🔀 Union
● Like a structure, but all members share the same memory.
📁 File Handling
ns
● Let’s you read and write data to files (like .txt, .bin).
● Types of Files:
tio
○ Text → human readable
ui
○ Binary → machine readable
● Modes: tT
○ "r" → read
en
○ "w" → write
○ "a" → append
om
A+B : https://classplusapp.com/w/wlp/cjzgt/ccat-videos-section-a-and-b
A+B+C : https://classplusapp.com/w/wlp/cjzgt/ccat-videos-section-a-and-b-and-c