C Programming Syntax Cheat Sheet
1. Basic Structure
#include <stdio.h>
int main() {
// Code
return 0;
2. Data Types and Modifiers
int, float, double, char
Modifiers: short, long, signed, unsigned
3. Variables and Constants
int a = 10;
const float PI = 3.14;
4. Input/Output
scanf("%d", &a);
printf("Value: %d", a);
5. Operators
Arithmetic: +, -, *, /, %
Assignment: =, +=, -=, etc.
Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, !
Bitwise: &, |, ^, ~, <<, >>
6. Control Statements
if (condition) { }
else if (condition) { }
else { }
switch (variable) {
case 1: break;
default: break;
while (condition) { }
do { } while (condition);
for (int i = 0; i < 10; i++) { }
7. Functions
return_type function_name(parameters) {
// code
return value;
8. Arrays and Strings
int arr[5] = {1, 2, 3, 4, 5};
char str[] = "Hello";
9. Pointers
int *ptr;
ptr = &a;
10. Structures
struct Person {
char name[20];
int age;
};
11. File Handling
FILE *fp;
fp = fopen("file.txt", "r");
fclose(fp);