How do two-dimensional arrays work in C?
Learn how a 2d array in C is declared, initialised and stored in row-major memory, with loops, a matrix example and dynamic allocation.
313 posts about C: questions with answers, tutorials and articles, newest first.
Learn how a 2d array in C is declared, initialised and stored in row-major memory, with loops, a matrix example and dynamic allocation.
A beginner guide to arrays in C: declaring, initialising, looping, finding the length and avoiding out-of-bounds errors, with complete examples.
Learn how command line arguments work in C: what argc and argv hold, how to validate them, convert them to numbers and parse simple flags.
Learn how variadic functions work in C with stdarg.h, including counts, sentinels, format strings, promotions and the common pitfalls.
Storage classes in C control how long a variable lives and who can see it. See auto, register, extern and static with clear, runnable examples.
Scope is where a C variable's name is visible; lifetime is how long it exists. See local, global and static variables with examples and common bugs.
Recursion in C means a function calls itself until a base case stops it. See how the call stack works, with factorial and Fibonacci examples and pitfalls.
C passes every argument by value. See why changes to a parameter do not affect the caller and how passing pointers gives call by reference behaviour.
A function prototype tells the compiler a function's signature before it is defined, so calls can be checked. Learn the syntax, headers and common mistakes.
A C function needs a return type, a name, parameters and a body. See how declarations differ from definitions and how to split functions across files.
The goto statement jumps to a label in the same function. See its syntax, the rules, why it has a bad reputation and the two cases where it is still useful.
Print stars and numbers in triangles, pyramids and diamonds with nested for loops. Learn the row, space and symbol formulas behind each pattern.
break leaves the nearest loop or switch; continue skips to the next iteration. See how each behaves in for and while loops and nested code.
A while loop may run zero times; a do while loop always runs once. Compare syntax and use cases with clear C examples.
A for loop repeats code using initialisation, condition and update in one line. Learn the execution order, array traversal and common pitfalls.
The ternary operator picks one of two values in a single expression. See its syntax, type rules, precedence and when to use if else instead.
A switch jumps to the case label that matches an integer expression. Learn break, default, fall-through and the rules for case labels.
The if else statement runs code depending on a condition. Learn the syntax, else if chains, logical operators and the mistakes to avoid.
Signed integer overflow is undefined behavior in C while unsigned wraps. Learn how to check operands, use checked helpers and catch bugs early.
Undefined behavior means the C standard sets no rules for invalid operations. See common causes, how compilers exploit it and how to find it.