From the course: C++ Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Increment and decrement operators - C++ Tutorial
From the course: C++ Essential Training
Increment and decrement operators
- [Narrator] C++ provides unary operators for incrementing and decrementing values. So, unary operator means that it has only one operand. Let's go ahead and create a variable. And then we'll go ahead and we'll print that variable while incrementing it. So this plus-plus in front of the X, that is a unary increment operator. It's unary because it has one operand, the X, and it simply increments the X to its next value before returning it. And so, well, let's just do this a few times here. We'll build and run this. See that our result is X is 6, 7, and 8. So what's happening here, is it first increments the value, and then it returns the value. There's also a decrement version of this. Looks like that, and it works exactly the same. It decrements the value, and then returns it 4, 3, and 2. There's another version of each of these that first returns the value, and then increments or decrements it. And that's the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.