How do you use the const keyword in C?
The const keyword makes an object read-only. See how it works with variables, pointers and function parameters, and why casting it away is risky.
313 posts about C: questions with answers, tutorials and articles, newest first.
The const keyword makes an object read-only. See how it works with variables, pointers and function parameters, and why casting it away is risky.
Pre-increment ++i returns the new value and post-increment i++ returns the old one. Learn when it matters and which expressions are undefined.
Operator precedence and associativity decide how C groups an expression. See the precedence table, worked examples and the classic mistakes.
Bitwise operators in C work on individual bits. Learn &, |, ^, ~, << and >>, the set, clear and toggle idioms, flags and the precedence traps.
Relational operators compare values and logical operators combine conditions in C. See short-circuit evaluation, truth rules and common bugs.
Arithmetic operators in C add, subtract, multiply, divide and take remainders. See precedence, integer division, ++ and -- and overflow pitfalls.
The sizeof operator returns the size in bytes of a type or an expression as a size_t. See how to use it with arrays, structs and malloc.
Type casting in C converts a value from one type to another, automatically or with a cast operator. Learn the rules and the bugs they cause.
Fixed-width integer types such as int32_t and uint8_t from stdint.h guarantee a size in bits. See when to use them and how to print and combine them safely.
Learn how signed and unsigned integers differ in C: value ranges, two's complement, overflow behaviour, comparison pitfalls and guidance on which to choose.
Understand how char stores characters as small integers, how the ASCII table maps letters and digits to numbers, and how to convert and classify characters safely.
Compare float and double in C by size, precision and range, see real rounding errors in code, and learn when to choose each type and how to compare them safely.
The integer types in C are char, short, int, long and long long. See their guaranteed minimum sizes, real sizes on common systems, ranges and fixed-width alternatives.
Learn how scanf in C reads numbers, characters and strings, why it needs the address-of operator, and how to handle bad input and leftover newlines safely.
Learn how printf prints formatted output in C, including format specifiers, width and precision, length modifiers and the mistakes that cause undefined behaviour.
C17 is a bug-fix edition of C11, and C23 is the newest standard with bool, nullptr, constexpr, typeof and #embed. Choose one with -std=c17 or -std=c23.
Use // for single-line comments and /* */ for blocks. Block comments do not nest, and the compiler removes all comments before translation.
The main function is where a hosted C program starts. It returns an int exit status, where 0 means success, and can read arguments through argc and argv.
A C program is preprocessed, compiled to assembly, assembled to an object file and linked into an executable. GCC options let you stop and inspect each step.
A C hello world needs stdio.h, an int main(void) function and a printf call. Compile it with gcc and run it from your terminal.