C
Understand how the computer really works
A solid engineering foundation: types and operators, loops, arrays and strings, memory and pointers, functions and structs.
- 34 lessons
- 7 chapters
- Arabic & English
Your progress
What's inside
Lessons go from the basics to advanced topics. Read them in order, or jump to what you need.
Chapter 1
Getting Started
- 1C IntroductionMeet C: what it is, where it is used, and why learning it is a strong start for any programmer.
- 2C Get StartedSet up your environment: install the GCC compiler, write your first program in main.c, then compile and run it from the terminal.
- 3C SyntaxLearn the structure behind every C program: the #include line, the main() function, statements, semicolons, and return 0.
- 4C Output (Print Text)Use the printf() function to print text to the screen, and escape sequences such as \n to start new lines.
- 5C CommentsComments are notes that explain your code, and the compiler ignores them completely. C supports single-line // comments and multi-line /* */ comments.
Chapter 2
Variables & Data
- 6C VariablesVariables are containers for storing data values. Learn how to declare variables, assign and change their values, and print them with printf().
- 7C Format SpecifiersFormat specifiers such as %d, %f, %c and %s tell printf() what type of value to print, and control how it looks: decimal places and field width.
- 8C Data TypesEvery variable in C has a data type such as int, float, double or char. Learn their sizes and format specifiers, and how to measure any type with sizeof.
- 9C Type ConversionConvert values from one data type to another, either automatically (implicit conversion) or manually (explicit casting), and avoid the classic integer division trap.
- 10C ConstantsUse the const keyword or the #define directive to create fixed values that cannot change while the program runs.
- 11C OperatorsOperators perform operations on variables and values. Learn the arithmetic, assignment, comparison, logical, and increment/decrement operators.
- 12C BooleansIn C, any non-zero value is true and zero is false. Learn how to use the bool type from <stdbool.h> to write clearer conditions with true and false.
Chapter 3
Control Flow
- 13C If...ElseUse if, else if and else to run different code depending on whether a condition is true or false, and meet the short-hand ternary operator.
- 14C SwitchUse the switch statement to pick one of many code blocks to run based on the value of a variable — and don't forget break!
- 15C While LoopLoops repeat a block of code as long as a condition is true. Learn the while loop and the do/while loop, which always runs at least once.
- 16C For LoopWhen you know exactly how many times to repeat something, use the for loop. Learn its three parts, counting in different steps, and nested loops.
- 17C Break and ContinueUse break to jump out of a loop early, and continue to skip the current round and go straight to the next one.
Chapter 4
Arrays & Strings
- 18C ArraysArrays store multiple values of the same type in a single variable. Learn how to create them, access and change their elements, loop through them, and get their length with sizeof.
- 19C Multidimensional ArraysA multidimensional array is an array of arrays. Learn two-dimensional arrays, which work like tables with rows and columns, and how to access and loop through their elements.
- 20C StringsC has no string type: text is stored in arrays of characters that end with the null character '\0'. Learn how to create, print, access and modify strings.
- 21C String FunctionsThe <string.h> library provides ready-made string functions: strlen() to get the length, strcpy() to copy, strcat() to join, and strcmp() to compare.
- 22C User InputRead numbers and words from the keyboard with scanf(), read full lines with fgets(), and learn the risks of each and how to avoid them.
Chapter 5
Memory & Pointers
- 23C Memory AddressEvery variable is stored at a location in memory that has an address. Use the & operator to get a variable's address and the %p specifier to print it.
- 24C PointersA pointer is a variable that stores the memory address of another variable. Learn to declare pointers, access values through them with *, and change values using them.
- 25C Pointers and ArraysAn array's name works as a pointer to its first element. Learn how to access array elements with pointers and how pointer arithmetic works.
- 26C Dynamic MemoryReserve memory while your program runs with malloc(), calloc() and realloc(), always check for NULL, and give the memory back with free().
Chapter 6
Functions
- 27C FunctionsA function is a block of code that runs only when it is called. Learn how to create and call your own functions, and how to declare them in advance with a prototype.
- 28C Function ParametersPass information to functions through parameters, send results back with return, and understand the difference between passing by value and passing pointers and arrays.
- 29C Variable ScopeA variable can only be used inside the region where it was created. Learn the difference between local and global variables, and what block scope means.
- 30C RecursionRecursion is when a function calls itself. Learn why every recursive function needs a base case, with sum and factorial examples.
- 31C Math FunctionsThe <math.h> library provides ready-made math functions such as sqrt(), pow(), ceil(), floor() and fabs(). Remember the -lm option when compiling with GCC on Linux.
Chapter 7
Structures
- 32C Structures (structs)Structures group several related variables, possibly of different types, under one name. Learn to define structs, access their members, create arrays of structs, and use pointers with the -> operator.
- 33C EnumsAn enum is a special type that represents a group of named constants. Use enums to make your code clearer, especially with switch statements.
- 34C FilesCreate, write, append to and read files with fopen(), fprintf(), fgets() and fclose(), and choose the right file mode for each task.