C
C is the foundational systems programming language. Understanding C gives you a mental model of how computers work memory, pointers, compilation, and hardware interaction that every other language abstracts away.
Contents 6 Sections
1C Fundamentals
#include <stdio.h>
#include <stdlib.h>
#include <string.h>int main() { // Basic types int age = 30; float price = 9.99f; double pi = 3.14159265; char grade = 'A'; char name[] = "Sufi"; // string = char array
// printf format specifiers printf("Name: %s, Age: %d, Price: %.2f\n", name, age, price);
// Arrays int nums[5] = {10, 20, 30, 40, 50}; int size = sizeof(nums) / sizeof(nums[0]); // 5
// Loops for (int i = 0; i < size; i++) { printf("%d ", nums[i]); }
return 0; // 0 = success } ```
2Pointers The Heart of C
int x = 42;
int *ptr = &x; // pointer to xprintf("%d\n", x); // 42 value printf("%p\n", ptr); // address of x printf("%d\n", *ptr); // 42 dereference
*ptr = 100; // modify x through pointer printf("%d\n", x); // 100
// Pointer arithmetic int arr[] = {1, 2, 3, 4, 5}; int *p = arr; // points to arr[0] printf("%d\n", *(p + 2)); // arr[2] = 3
// Function pointers int add(int a, int b) { return a + b; } int (*fn)(int, int) = add; printf("%d\n", fn(3, 4)); // 7
// NULL pointer check ALWAYS int *safe = NULL; if (safe != NULL) { printf("%d\n", *safe); } ```
3Memory Management
#include <stdlib.h>// Stack memory automatic, fast, limited size int stack_arr[100]; // deallocated when function returns
// Heap memory manual, flexible, large int *heap_arr = malloc(100 * sizeof(int)); if (heap_arr == NULL) { fprintf(stderr, "Memory allocation failed\n"); exit(1); }
// Use the memory for (int i = 0; i < 100; i++) { heap_arr[i] = i * 2; }
// MUST free heap memory to prevent leaks free(heap_arr); heap_arr = NULL; // avoid dangling pointer
// calloc allocate and zero-initialize int *zeroed = calloc(50, sizeof(int));
// realloc resize allocation int *resized = realloc(heap_arr, 200 * sizeof(int)); if (resized == NULL) { free(heap_arr); exit(1); } heap_arr = resized; ```
4Structs & Custom Types
#include <stdio.h>
#include <string.h>typedef struct { char name[50]; int age; float salary; } Employee;
typedef struct Node { int data; struct Node *next; // self-referential } Node;
// Struct initialization Employee emp = { .name = "Sufi", .age = 30, .salary = 95000.0f }; printf("%s earns $%.2f\n", emp.name, emp.salary);
// Pointer to struct Employee *ptr = &emp; printf("%s\n", ptr->name); // arrow operator for pointer printf("%s\n", (*ptr).name); // equivalent
// Linked list node creation Node *new_node(int val) { Node *n = malloc(sizeof(Node)); n->data = val; n->next = NULL; return n; } ```
5File I/O & System Calls
#include <stdio.h>// Writing a file FILE *f = fopen("output.txt", "w"); if (f == NULL) { perror("fopen"); return 1; } fprintf(f, "Line 1\nLine 2\n"); fclose(f);
// Reading a file FILE *r = fopen("output.txt", "r"); char line[256]; while (fgets(line, sizeof(line), r) != NULL) { printf("%s", line); } fclose(r);
// Binary I/O Employee emp = { "Sufi", 30, 95000.0f }; FILE *bin = fopen("data.bin", "wb"); fwrite(&emp, sizeof(Employee), 1, bin); fclose(bin);
// Read binary Employee loaded; FILE *bin2 = fopen("data.bin", "rb"); fread(&loaded, sizeof(Employee), 1, bin2); fclose(bin2); printf("Loaded: %s\n", loaded.name); ```
6C in Modern Context
- Where C is Still Essential
- Operating system kernels (Linux, macOS, Windows are mostly C)
- Embedded systems and IoT firmware
- Performance-critical libraries (OpenSSL, SQLite, NumPy core)
- Device drivers and real-time systems
- Language runtime implementations (CPython, Ruby MRI)
- Common Pitfalls
- Buffer overflow: writing past array bounds (major security vulnerability)
- Use after free: accessing memory after free()
- Dangling pointers: pointer to freed/stack memory
- Integer overflow: wrapping around at max value
- Uninitialized variables: undefined behavior
Compilation & Tooling
``bash
gcc -Wall -Wextra -O2 -g main.c -o program # compile with warnings
valgrind ./program # detect memory leaks
gdb ./program # debugger
clang-tidy main.c # static analysis
``
Explore the Full Portfolio
This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.
The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.
For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.