'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });
There is a big distinction between the suffix and prefix versions of ++.
- In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression.
- In the postfix version (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i. So basically it first assigns a value to expression and then increments the variable.
Example
Let's look at some code to get a better understanding −
#include<iostream>using namespace std;int main() { int x = 3, y, z; y = x++; z = ++x; cout << x << ", " << y << ", " << z; return 0;}
Output
This would give us the output −
5, 3, 5
Why is this? Let's look at it in detail −
- Initialize x to 3
- Assign y the value we get by evaluating the expression x++, ie, the value of x before increment then increment x.
- Increment x then assign z the value we get by evaluating the expression ++x, ie, value of x after the increment.
- Print these values
Updated on: 08-Sep-2023
30K+ Views
- Related Articles
- What is the difference between ++i and i++ in c?
- Is there a performance difference between i++ and ++i in C++?
- Is there a performance difference between i++ and ++i in C++ program?
- What is the difference between Isolated and memory-mapped I/O?
- Difference between %d and %i format specifier in C
- Difference between %d and %i format specifier in C language.
- Difference Between E-Ticket and I-Ticket
- What is the difference Between C and C++?
- What is the difference between | and || operators in c#?
- What is the difference between JavaScript and C++?
- What is the difference between overriding and shadowing in C#?
- What is the difference between String and string in C#?
- What is the difference between literal and constant in C#?
- What is the difference between size_t and int in C++?
- What is the difference between iostream and iostream.h in C++?
Advertisem*nts
'; adpushup.triggerAd(ad_id); });