Basic Structure
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
Variables
int a = 10;
float b = 3.14;
char c = 'A';
const int x = 5;
Input / Output
printf("Value: %d", a);
scanf("%d", &a);
scanf("%f", &b);
scanf(" %c", &c);
Operators
a + b
a - b
a * b
a / b
a % b
Conditionals
if (a == b) { }
if (a != b) { }
if (a > b) { }
else { }
switch(x) { case 1: break; }
Loops
for(int i=0; i<5; i++) { }
while(a < 10) { }
do { } while(a < 10);
Functions
int add(int a, int b) { return a+b; }
void hello() { printf("Hi"); }
int result = add(2,3);
Arrays
int arr[5];
int arr[3] = {1,2,3};
arr[0] = 10;
printf("%d", arr[0]);
Strings
char str[] = "Hello";
printf("%s", str);
scanf("%s", str);
Pointers
int *p;
p = &a;
printf("%d", *p);
*p = 20;
Structures
struct Person { int age; };
struct Person p1;
p1.age = 25;
File Handling
FILE *f = fopen("file.txt", "r");
fprintf(f, "Hello");
fscanf(f, "%d", &a);
fclose(f);
Preprocessor
#define PI 3.14
#include <math.h>
#ifdef DEBUG
#endif