0% found this document useful (0 votes)
133 views10 pages

C Language Cheat Sheet

This document is a comprehensive cheat sheet for the C programming language, covering its history, keywords, data types, operators, control structures, functions, arrays, strings, preprocessor directives, structures, unions, and file handling. It provides essential information and examples for each topic, making it a useful resource for students preparing for the CCAT exam. Additionally, it includes links to free cheat sheets for all subjects related to CCAT.

Uploaded by

mrnoonekiid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views10 pages

C Language Cheat Sheet

This document is a comprehensive cheat sheet for the C programming language, covering its history, keywords, data types, operators, control structures, functions, arrays, strings, preprocessor directives, structures, unions, and file handling. It provides essential information and examples for each topic, making it a useful resource for students preparing for the CCAT exam. Additionally, it includes links to free cheat sheets for all subjects related to CCAT.

Uploaded by

mrnoonekiid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Last Moment Tuitions

C Language Cheat Sheet for CCAT

🕰️ 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:​

○​ int → means a number​

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

🧮 Data Types, Type Modifiers & Qualifiers


●​ Data Types tell the computer what kind of value you're using:​
M

○​ int → whole numbers (like 5, -3)​


st

○​ float → decimal numbers (like 3.14)​

○​ char → single letters (like 'A')​


La

●​ Type Modifiers like short, long, unsigned change the size or range.​
Example:​

○​ unsigned int means no negative numbers allowed.​

○​ long int allows bigger numbers.​

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

●​ Qualifiers like const and volatile:​

○​ const int a = 10; → This means the value of a can't change.​

➕ Operators, Priority & Associativity


●​ Operators are symbols used to do calculations or comparisons.​

ns
○​ +, -, *, /, % → basic math​

tio
○​ ==, !=, <, > → comparisons​

●​ Priority: Some operators are done before others. Like in maths:​

ui
○​ * and / happen before + and -​
tT
●​ Associativity: Tells which side the operation starts from (usually left to right).​
en

🔁 Decision Control (if-else, switch)


om

●​ Makes your program choose between options.​


M

if-else is like asking:​


"If I have money, I’ll buy chocolate. Else, I’ll stay home."​
st

if (money > 0) {
La

buy_chocolate();

} else {

stay_home();

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

switch is used when there are many choices:​



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

🔄 Loops (while, do-while, for) + Jump

ns
●​ Loops let you repeat tasks:​

○​ while → check condition before running​

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:​

○​ break → exits loop early​


M

○​ continue → skips to next loop round​


st

○​ goto → jumps to a label (not recommended)

🧩 Functions
La

Think of functions as small tasks or tools inside your program.​


They help you organize your code and avoid repeating the same thing again and again.

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

Example:

int add(int a, int b) {

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

🔁 How Data is Passed to Functions


📤 Pass by Value:​
om

●​
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.

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

🏷️ Storage Classes
They tell:

●​ Where a variable is stored​

●​ How long it exists in memory​

Examples:

ns
●​ auto → default​

●​ static → remembers its value​

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

int *ptr = &a; // &a means address of a

●​ NULL pointer: Points to nothing.​

●​ Void pointer: Can point to any type.​


M

●​ Wild pointer: Not initialized. Dangerous!​


st

●​ Pointer Arithmetic: You can move to next/previous memory.​

●​ Function Pointer: Pointer that stores address of a function.​


La

Prepare for CDAC CCAT Exam with LMT Study Material

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

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

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.

📍 Example of 1D Array (One Row)


●​ int marks[5] = {10, 20, 30, 40, 50};

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

2D Array (Like a Table or Grid)

●​ int mat[2][2] = {{1, 2}, {3, 4}};


M

➡️ Looks like this:


●​ 1 2
st

●​ 3 4
La

Types of Arrays:

✅ Static Array:​
Size is fixed from the beginning (before the program runs).​

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

🔄 Dynamic Array:​
Size is decided while the program is running, using malloc().

Arrays and Pointers:

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 name[] = "Alice"; tT


This is the same as:
en
●​ {'A', 'l', 'i', 'c', 'e', '\0'}

➡️ The '\0' at the end means “end of the string” in C.


om

🎯 String Functions (Already Made in C):


M

●​ strlen() → Counts how many letters are in the string​


st

●​ strcpy() → Copies one string into another​


La

✨ Ways to Store Many Strings:


1.​ 2D Array:​

●​ char names[5][10];

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

➡️ Think of it as 5 rows of strings, each with 10 characters.


2.​ Array of Pointers:​

●​ char *names[5];

➡️ A list of 5 separate string pointers.

💻 Command Line Arguments:

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

●​ These are instructions given to the compiler before code runs.​


om

○​ #include <stdio.h> → includes a file​

○​ #define PI 3.14 → makes a shortcut​


M

○​ #pragma → gives special instruction to compiler​


st

○​ # and ## used to make macros more flexible​

●​ Macro vs Function:​
La

○​ Macro is faster (no function call), but may cause errors.​

○​ Function is safer, but slightly slower.​

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

🏗️ 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
};

Now you can create a student like this:


tT
en
●​ struct Student s1 = {"Alice", 16, 89.5};

You can access the values like this:


om

printf("%s", s1.name); // prints name

printf("%d", s1.age); // prints age

printf("%.1f", s1.marks); // prints marks


M

💡 In short:
st
La

●​ Structure = Group of different data types in one name​

●​ Helps organize related information (like a record)​

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt
Last Moment Tuitions

🔀 Union
●​ Like a structure, but all members share the same memory.​

●​ Only one member can hold a value at a time.​

●​ Useful to store different types in same space.

📁 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

○​ "rb", "wb" → binary mode​

●​ Sequential Access: Read one line after another.​


M

●​ Random Access: Jump to any part of file.​


st

●​ Buffer Read/Write: Temporarily hold data before writing.​


La

●​ Binary Read/Write: Save space and is faster.

Prepare for CDAC CCAT Exam with LMT Study Material

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

Get FREE Cheat Sheet of ALL Subject of CCAT :


https://play.google.com/store/apps/details?id=co.jones.cjzgt

You might also like