C programming is one of the most widely used programming languages for learning computer programming fundamentals. It is widely used in system programming, embedded systems development, operating systems, and microcontroller programming.
A C programming cheat sheet provides a quick reference to the most important syntax, operators, functions, and concepts used in C. Instead of searching through long tutorials, students and developers can quickly revise key topics from a single page.
This C language cheat sheet is useful for beginners, engineering students, and developers preparing for technical interviews. You can bookmark this page or download the PDF for quick revision whenever needed.
Every C program follows a simple structure that includes header files, the main function, and program statements.
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
| Component | Description |
|---|---|
| #include | Includes header files |
| main() | Entry point of the program |
| printf() | Displays output |
| return 0 | Ends the program |
Data types specify the type of data that a variable can store.
| Data Type | Example | Description |
|---|---|---|
| int | int a = 10; | Stores integer values |
| float | float x = 3.14; | Stores decimal numbers |
| double | double d = 12.567; | Higher precision decimal |
| char | char c = 'A'; | Stores a single character |
| Type | Size |
|---|---|
| char | 1 byte |
| int | 4 bytes |
| float | 4 bytes |
| double | 8 bytes |
Format specifiers are used with input and output functions such as printf() and scanf().
| Specifier | Meaning |
|---|---|
| %d | Integer |
| %f | Float |
| %lf | Double |
| %c | Character |
| %s | String |
printf("%d", number);
Operators perform operations on variables and values.
| Operator | Example |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
int sum = a + b;
Used for comparison.
| Operator | Meaning |
|---|---|
| == | Equal |
| != | Not equal |
| > | Greater than |
| < | Less than |
| >= | Greater or equal |
| <= | Less or equal |
| Operator | Meaning |
|---|---|
| && | Logical AND |
| || | Logical OR |
| ! | Logical NOT |
if(a > b){
printf("A is greater");
}
if(a > b)
printf("A is greater");
else
printf("B is greater");
switch(n){
case 1:
printf("One");
break;
default:
printf("Invalid");
}
for(int i=0;i<5;i++){
printf("%d",i);
}
while(i<5){
printf("%d",i);
i++;
}
do{
printf("%d",i);
i++;
}while(i<5);
int arr[5] = {1,2,3,4,5};
printf("%d", arr[0]);
datatype array_name[size];
int numbers[10];
In C, strings are stored as character arrays.
char name[20] = "IIES";
printf("%s", name);
| Function | Description |
|---|---|
| strlen() | Length of string |
| strcpy() | Copy string |
| strcat() | Concatenate strings |
| strcmp() | Compare strings |
int add(int a,int b){
return a + b;
}
int result = add(5,3);
int a = 10;
int *p = &a;
printf("%d", *p);
| Symbol | Meaning |
|---|---|
| & | Address of variable |
| * | Pointer value |
Pointers are very important in embedded systems and system programming.
C allows dynamic memory allocation using functions from stdlib.h.
int *ptr; ptr = (int*)malloc(5 * sizeof(int)); free(ptr);
| Function | Purpose |
|---|---|
| malloc() | Allocate memory |
| calloc() | Allocate and initialize memory |
| realloc() | Resize memory |
| free() | Deallocate memory |
struct Student{
int id;
char name[20];
};
struct Student s1; s1.id = 1;
| Storage Class | Description |
|---|---|
| auto | Default local variable |
| static | Retains value between function calls |
| extern | Global variable declaration |
| register | Stored in CPU register |
| Operator | Meaning |
|---|---|
| & | AND |
| | | OR |
| ^ | XOR |
| ~ | NOT |
| << | Left shift |
| >> | Right shift |
int result = a & b;
FILE *fp;
fp = fopen("data.txt","w");
fprintf(fp,"Hello");
fclose(fp);
| Mode | Description |
|---|---|
| r | Read |
| w | Write |
| a | Append |
| Header File | Purpose |
|---|---|
| stdio.h | Input Output |
| stdlib.h | Memory management |
| string.h | String operations |
| math.h | Mathematical functions |
| time.h | Time functions |
Escape characters are used inside strings.
| Escape Character | Meaning |
|---|---|
| \n | New line |
| \t | Tab |
| \ | Backslash |
| " | Double quote |
printf("Hello\nWorld");
C language contains reserved keywords that cannot be used as variable names.
Some common C keywords include:
int, char, float, double, if, else, switch, case, break, continue, return, struct, typedef, static, extern
Students preparing for programming interviews should revise the following topics:
These topics are frequently asked in technical interviews and embedded systems programming roles.
For quick offline learning, you can download the C Programming Cheat Sheet PDF and use it as a quick reference while coding or preparing for interviews.
Download C Programming Cheat Sheet PDFThis C programming quick reference guide is useful for:
Indian Institute of Embedded Systems – IIES