| Concept | Syntax | Example |
|---|---|---|
| Include Header | #include <header> | #include <stdio.h> |
| Main Function | int main() { ... } | int main() { return 0; } |
| Print Statement | printf("text"); | printf("Hello World"); |
| Input Statement | scanf("%d", &var); | scanf("%d", &num); |
| Comments | // single line /* multi */ | // This is comment |
| Type | Size | Range | Example |
|---|---|---|---|
| int | 4 bytes | -2,147,483,648 to 2,147,483,647 | int age = 25; |
| char | 1 byte | -128 to 127 | char grade = 'A'; |
| float | 4 bytes | 6 decimal precision | float price = 19.99; |
| double | 8 bytes | 15 decimal precision | double pi = 3.14159; |
| void | 0 bytes | No value | void func(); |
| Category | Operator | Example | Description |
|---|---|---|---|
| Arithmetic | + - * / % | a + b | Addition, Subtraction, Multiplication, Division, Modulus |
| Relational | == != < > <= >= | a == b | Comparison operators |
| Logical | && || ! | a && b | AND, OR, NOT |
| Assignment | = += -= *= /= %= | a += b | Assignment operators |
| Bitwise | & | ^ ~ << >> | a & b | Bitwise operations |
| Structure | Syntax | Example |
|---|---|---|
| If Statement | if(condition) { ... } | if(x > 0) { printf("Positive"); } |
| If-Else | if(c) { ... } else { ... } | if(x > 0) { printf("Pos"); } else { printf("Neg"); } |
| Switch | switch(var) { case x: ... break; } | switch(day) { case 1: printf("Mon"); break; } |
| For Loop | for(init; cond; inc) { ... } | for(i=0; i<10; i++) { printf("%d", i); } |
| While Loop | while(condition) { ... } | while(x > 0) { x--; } |
| Do-While | do { ... } while(condition); | do { scanf("%d", &x); } while(x != 0); |
| Concept | Syntax | Example |
|---|---|---|
| Function Declaration | return_type name(type param); | int add(int a, int b); |
| Function Definition | return_type name(type param) { ... } | int add(int a, int b) { return a+b; } |
| Function Call | name(arg1, arg2); | result = add(5, 3); |
| Recursion | function calls itself | int fact(int n) { if(n<=1) return 1; else return n*fact(n-1); } |
| Concept | Syntax | Example |
|---|---|---|
| Array Declaration | type name[size]; | int arr[10]; |
| Array Initialization | type name[] = {a, b, c}; | int nums[] = {1, 2, 3}; |
| Access Element | name[index] | arr[0] = 5; |
| 2D Array | type name[row][col]; | int matrix[3][3]; |
| Concept | Syntax | Example |
|---|---|---|
| Pointer Declaration | type *name; | int *ptr; |
| Address Operator | &variable | ptr = &var; |
| Dereference Operator | *pointer | value = *ptr; |
| Pointer Arithmetic | ptr++, ptr--, ptr+n | ptr++; // move to next address |
| Function | Declaration | Purpose | Example |
|---|---|---|---|
| strlen | int strlen(char *str); | Get string length | len = strlen("hello"); |
| strcpy | char *strcpy(char *dest, char *src); | Copy string | strcpy(dest, src); |
| strcat | char *strcat(char *dest, char *src); | Concatenate strings | strcat(str1, str2); |
| strcmp | int strcmp(char *str1, char *str2); | Compare strings | result = strcmp(s1, s2); |
| gets | char *gets(char *str); | Read string | gets(buffer); |
| puts | int puts(char *str); | Print string | puts("Hello"); |
| Function | Declaration | Purpose | Example |
|---|---|---|---|
| malloc | void *malloc(size_t size); | Allocate memory | ptr = malloc(10 * sizeof(int)); |
| calloc | void *calloc(size_t n, size_t size); | Allocate and initialize to 0 | ptr = calloc(10, sizeof(int)); |
| realloc | void *realloc(void *ptr, size_t size); | Resize allocated memory | ptr = realloc(ptr, 20 * sizeof(int)); |
| free | void free(void *ptr); | Free allocated memory | free(ptr); |
| Directive | Usage | Example | Description |
|---|---|---|---|
| #include | Include header files | #include <stdio.h> | Includes header files |
| #define | Define macros | #define PI 3.14159 | Defines constants/macros |
| #ifdef | Conditional compilation | #ifdef DEBUG ... #endif | Compile conditionally |
| #ifndef | Check if not defined | #ifndef HEADER_H ... #endif | Guard against multiple inclusion |
| #if #else #endif | Conditional compilation | #if x>5 ... #else ... #endif | Conditional compilation |
| Concept | Syntax | Example |
|---|---|---|
| Structure | struct name { ... }; | struct Student { int id; char name[20]; }; |
| Structure Variable | struct name var; | struct Student s1; |
| Access Member | var.member | s1.id = 10; |
| Union | union name { ... }; | union Data { int i; float f; }; |
| Typedef | typedef old new; | typedef struct Student Std; |
| Function | Declaration | Purpose | Example |
|---|---|---|---|
| fopen | FILE *fopen(char *name, char *mode); | Open file | fp = fopen("file.txt", "r"); |
| fclose | int fclose(FILE *fp); | Close file | fclose(fp); |
| fread | size_t fread(void *ptr, size_t size, size_t n, FILE *fp); | Read from file | fread(buffer, 1, 10, fp); |
| fwrite | size_t fwrite(void *ptr, size_t size, size_t n, FILE *fp); | Write to file | fwrite(buffer, 1, 10, fp); |
| fprintf | int fprintf(FILE *fp, char *format, ...); | Formatted write | fprintf(fp, "%d", num); |
| fscanf | int fscanf(FILE *fp, char *format, ...); | Formatted read | fscanf(fp, "%d", &num); |