Syntax and Functions

Increment Operator

How prefix and postfix increment differ and when ++i is the better choice.

What Is an Increment in Computing?

Learn what an increment means in computing, where counters and loop variables use one, and how C++ writes an increment using the ++ operator.

1 min read

What Is the Prefix Increment Operator?

The prefix increment operator adds one before the value is used. Learn how ++x works in C++, how it differs from x++, and why it matters in code.

2 min read

Why Is ++i Better Than i++?

Is ++i really better than i++? Learn why C++ programmers often prefer prefix increment, when postfix still makes sense, and what the copy costs.

2 min read

Related topics

More in syntax and functions

Primitive Data Types The built in C++ types, type casting and how other languages group data types. long long What the long long type holds and when you need a long integer. Signed vs Unsigned How signed and unsigned integers differ and how they look in binary. double and float What double stores, how big a float is and how to print floating point values. Integer Limits The minimum and maximum int values in C++ and how they compare with 1e9. sizeof How the sizeof operator measures types in bytes and how big an int really is. typeof and decltype How decltype and typeof deduce types, with a look at typeof in JavaScript. Enums How enums work in C++ and C, with examples of why you would use one. Declaration and Initialization Designated initializers and the difference between declaring and initializing variables and arrays. Conditional Operator How the ternary conditional operator works and how conditional statements are written. Comparison Operators The operators that compare values in C++ and how logical OR fits in. Assignment Operators Plain and compound assignment, plus the address and dereference operators. Unary Operators The operators that act on a single operand and how they differ from ternary ones. Shift Operators How left and right shifts move bits, with small examples like 1 << n. Bitwise Operators XOR, NOT and the other bitwise operators, and how & differs from &&. Power Operator Whether C++ has an exponent operator and how to raise numbers to a power. Logical and Arithmetic Operators The OR operator and an overview of arithmetic and other C operators. Dot and Scope Operators How the dot operator reaches members and what the :: operator means. While Loops While loop syntax with examples and the three main kinds of loops. Do While Loops Example do while programs and how they compare with for and while loops. Break Statement How break exits loops and switch statements early. Switch Case How switch case statements work and when they beat a chain of ifs. If Else Statements If else syntax and how to build an else if ladder. goto What the goto jump statement does and how to use it in C and C++. Recursion How recursive functions work, why they need a base case and how they look in Python. Function Overloading Function overloading in C++, how it differs from overriding and from operator overloading. Function Prototypes What a function prototype is and how it relates to a function definition. Static Functions What static does to functions and variables and when to use it. inline What the inline keyword does and how inline functions differ from macros. const How const works in C++, the C keyword list and const in JavaScript. using namespace std What namespaces are, what std means and when to write std:: yourself. using The roles of the using keyword in C++, plus the ternary operator. cout How to print output with std::cout and the << operator. Lambda Functions How C++ lambdas are written, what type they have and why they are useful. std::function How std::function stores callable objects, plus count() and the types of functions in C. Functions as Arguments How to pass a function to another function using pointers and other callables. Function Pointer Arrays How to build arrays of function pointers, starting from what an array is. Header Guards How header guards stop a file from being included twice. Header Files What .h files are for, with a worked C++ header file example. The Preprocessor What the preprocessor does to your code before it is compiled. Macros How macros work, how to stringify one and why C++ often avoids them.