C Language Cheat Sheet
1. Variables and Data Types
int a = 10; // Integer variable
float b = 20.5; // Floating point variable
char c = 'A'; // Character variable
double d = 30.99; // Double-precision variable
2. Input and Output
printf("Hello, World!\n"); // Output to console
scanf("%d", &a); // Input an integer
3. Conditionals
if (a > 0) {
printf("a is positive\n");
} else {
printf("a is not positive\n");
}
4. Loops
// For loop
for (int i = 0; i < 5; i++) {
printf("%d\n", i);
}
// While loop
int i = 0;
while (i < 5) {
printf("%d\n", i);
i++;
}
5. Functions
int add(int x, int y) {
return x + y;
}
int result = add(5, 3);
printf("%d\n", result);
6. Arrays
int arr[5] = {1, 2, 3, 4, 5};
for (int i = 0; i < 5; i++) {
printf("%d\n", arr[i]);
}