C Programming Cheat Sheet for Quick Revision
C Programming Cheat Sheet for Quick Revision
1. Basic Syntax
Header: #include <stdio.h>
Main Function: int main() { return 0; }
Comments: // Single-line or /* Multi-line */
3. Operators
Arithmetic: +, -, *, /, %
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Bitwise: &, |, ^, ~, <<, >>
4. Control Structures
If-else:
Switch:
switch(choice) {
case 1: printf("One"); break;
default: printf("Other");
}
Loops:
5. Functions
Declaration: int add(int a, int b);
Definition:
7. Pointers
Declaration: int *p;
Assignment: int x = 10; p = &x;
Dereferencing: printf("%d", *p);
8. Structures
struct Student {
char name[20];
int age;
};
struct Student s1 = {"John", 20};
9. File Handling
FILE *fptr = fopen("file.txt", "r");
if (fptr != NULL) { fclose(fptr); }