1. Variables
int x = 10; // integer variable
float y = 20.5; // floating-point variable
char name = 'A'; // character variable
2. Data Types
int, float, char, double, long, short, unsigned
3. Operators
+, -, \*, /, %, ==, !=, >, <, >=, <=, &&, ||, !
4. Control Structures
if (condition) { code }
if (condition) { code } else { code }
switch (expression) { case value: code; break; }
for (init; condition; increment) { code }
while (condition) { code }
do { code } while (condition);
5. Loops
for (int i = 0; i < 10; i++) { code }
while (i < 10) { code; i++; }
do { code; i++; } while (i < 10);
6. Arrays
int scores[] = {90, 80, 70, 60};
char names[] = {'J', 'o', 'h', 'n'};
7. Functions
int add(int a, int b) { return a + b; }
void greet(char name[]) { printf("Hello, %s!", name); }
8. Pointers
int x = 10;
int* ptr = &x; // pointer to x
printf("%d", *ptr); // prints 10
9. Structures
struct Person {
char name[20];
int age;
};
10. Unions
union Data {
int i;
float f;
char str[20];
};
11. Enums
enum Color {
RED,
GREEN,
BLUE
};
12. Typedef
typedef int Integer;
Integer x = 10;
13. Sizeof Operator
int x = 10;
printf("%d", sizeof(x)); // prints 4
14. Casting
int x = 10;
float y = (float)x;
15. Bitwise Operators
int x = 10;
int y = x & 1; // bitwise AND
16. File Input/Output
FILE* file = fopen("example.txt", "r");
fscanf(file, "%d", &x);
17. Standard Library Functions
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
18. String Functions
char str[] = "Hello, World!";
printf("%s", str);
19. Memory Management
int* ptr = malloc(sizeof(int));
free(ptr);
20. Dynamic Memory Allocation
int* ptr = malloc(10 * sizeof(int));
21. Linked Lists
struct Node {
int data;
struct Node* next;
};
22. Stacks
struct Stack {
int data;
struct Stack* next;
};
23. Queues
struct Queue {
int data;
struct Queue* next;
};
24. Trees
struct TreeNode { int data; struct TreeNode* left; struct TreeNode* right;};
25. Binary Search Trees
struct BST {
int data;
struct BST* left;
struct BST* right;
};
26. Recursion
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
27. Macros
#define PI 3.14
28. Preprocessor Directives
#include <stdio.h>
#include <stdlib.h>
29. Command Line Arguments
int main(int argc, char* argv[]) {
printf("%s", argv[1]);
}
30. Exit Function
#include <stdlib.h>
exit(0);
31. Return Statement
return 0; // return from main
32. Switch Case
switch (x) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Other");
}
33. Break Statement
for (int i = 0; i < 10; i++) {
if (i == 5) break;
}
34. Continue Statement
for (int i = 0; i < 10; i++) {
if (i == 5) continue;
}
35. Goto Statement
goto label;
label: printf("Jumped to label");
36. Inline Functions
inline int square(int x) { return x * x; }
37. Function Pointers
void (*funcPtr)(int);
38. Variable Arguments
#include <stdarg.h>
void printNumbers(int count, ...) {
va_list args;
va_start(args, count);
for (int i = 0; i < count; i++) {
printf("%d", va_arg(args, int));
}
va_end(args);
}
39. Static Variables
static int count = 0;
40. Const Keyword
const int x = 10;
41. Volatile Keyword
volatile int x;
42. Register Keyword
register int x;
43. Type Casting
float y = (float)x;
44. Structs with Pointers
struct Node {
int data;
struct Node* next;
};
45. Function Returning Pointers
int* getPointer() {
int* ptr = malloc(sizeof(int));
return ptr;
}
46. Array of Pointers
int* arr[10];
47. Pointer to Function
void (*funcPtr)(int);
48. Multi-dimensional Arrays
int matrix[3][3];
49. String Manipulation
char str1[20] = "Hello";
char str2[20];
strcpy(str2, str1);
50. String Length
int length = strlen(str1);
51. String Comparison
if (strcmp(str1, str2) == 0) { printf("Strings are equal"); }
52. String Concatenation
strcat(str1, str2);
53. String Tokenization
char* token = strtok(str1, " ");
54. File Handling
FILE* file = fopen("file.txt", "w");
fprintf(file, "Hello, World!");
fclose(file);
55. Reading from File
FILE* file = fopen("file.txt", "r");
char buffer[100];
fgets(buffer, 100, file);
fclose(file);
56. Writing to File
FILE* file = fopen("file.txt", "a");
fprintf(file, "Appending text");
fclose(file);
57. Error Handling
if (file == NULL) { perror("Error opening file"); }
58. Command Line Arguments
int main(int argc, char* argv[]) { printf("%s", argv[1]); }
59. Preprocessor Macros
#define MAX 100
60. Conditional Compilation
#ifdef DEBUG
printf("Debug mode");
#endif
61. Inline Assembly
asm("movl $1, %eax");
62. Memory Alignment
struct __attribute__((aligned(8))) AlignedStruct { int x; };
63. C Standard Library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
64. Dynamic Arrays
int* arr = malloc(n * sizeof(int));
65. Reallocating Memory
arr = realloc(arr, newSize * sizeof(int));
66. Freeing Memory
free(arr);
67. Structs
struct Person { char name[50]; int age; };
68. Accessing Struct Members
struct Person p; strcpy(p.name, "John"); p.age = 30;
69. Nested Structs
struct Address { char city[50]; char state[50]; };
struct Person { char name[50]; struct Address address; };
70. Function Returning Struct
struct Person createPerson() { struct Person p; return p; }
71. Pointer to Struct
struct Person* ptr = &p;
72. Array of Structs
struct Person people[10];
73. Function with Struct Parameter
void printPerson(struct Person p) { printf("%s", p.name); }
74. Function Pointer with Struct
void (*funcPtr)(struct Person);
75. C99 Features
int arr[] = {1, 2, 3, 4, 5};
76. Variable Length Arrays
void function(int n) {
int arr[n]; // Variable length array
}
77. Designated Initializers
struct Point { int x; int y; };
struct Point p = {.y = 5, .x = 10};
78. Compound Literals
struct Point p = (struct Point){.x = 10, .y = 5};
79. Inline Functions
inline int max(int a, int b) { return (a > b) ? a : b; }
80. C11 Features
_Noreturn void myFunction() { while(1); }
81. Static Assertions
_Static_assert(sizeof(int) == 4, "Integers are not 4 bytes");
82. Threading
#include <pthread.h>
void* myThreadFunction(void* arg) { return NULL; }
pthread_t thread;
pthread_create(&thread, NULL, myThreadFunction, NULL);
83. Atomic Operations
#include <stdatomic.h>
atomic_int count = 0;
atomic_fetch_add(&count, 1);
84. C Preprocessor
#define SQUARE(x) ((x) * (x))
85. Macros with Arguments
#define MAX(a, b) ((a) > (b) ? (a) : (b))
86. Conditional Compilation
#ifdef DEBUG
printf("Debug mode");
#endif
87. File Handling
FILE* file = fopen("file.txt", "r");
if (file) { fclose(file); }
88. Error Handling
if (file == NULL) { perror("Error opening file"); }
89. Memory Management
int* ptr = malloc(10 * sizeof(int));
if (ptr) { free(ptr); }
90. String Functions
char str1[20] = "Hello";
char str2[20];
strcpy(str2, str1);
91. String Length
int length = strlen(str1);
92. String Comparison
if (strcmp(str1, str2) == 0) { printf("Strings are equal"); }
93. String Concatenation
strcat(str1, str2);
94. String Tokenization
char* token = strtok(str1, " ");
95. Command Line Arguments
int main(int argc, char* argv[]) { printf("%s", argv[1]); }
96. Preprocessor Macros
#define MAX 100
97. Conditional Compilation
#ifdef DEBUG
printf("Debug mode");
#endif
98. Inline Assembly
asm("movl $1, %eax");
99. Memory Alignment
struct __attribute__((aligned(8))) AlignedStruct { int x; };
100. C Standard Library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>