C Programming Last-Minute Revision Sheet
1. Structure of C Program
#include<stdio.h>
void main() {
// your code here
}
2. Data Types & Variables
- int → whole numbers
- float → decimal
- char → single character
Use scanf() to take input and printf() to display.
3. Operators
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <
- Logical: &&, ||, !
4. Conditional Statements
if (condition) { ... }
else { ... }
switch(choice) {
case 1: ...; break;
default: ...;
}
5. Loops
for (i=0; i<n; i++) {...}
while (condition) {...}
do {...} while (condition);
6. Functions
int add(int a, int b) {
return a + b;
}
7. Arrays
int a[5] = {1, 2, 3, 4, 5};
8. Strings
char name[20];
scanf("%s", name);
String functions: strlen(), strcpy(), strcmp()
9. Pointers
int a = 10, *p;
p = &a;
printf("%d", *p); // outputs 10
10. Structures
struct Student {
int roll;
char name[20];
};
11. File Handling
FILE *fp;
fp = fopen("file.txt", "w");
fprintf(fp, "Hello");
fclose(fp);