'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });
Postfix operators are unary operators that work on a single variable which can be used to increment or decrement a value by 1(unless overloaded). There are 2 postfix operators in C++, ++ and --.
In the postfix notation (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. For example,
Example
#include<iostream>using namespace std;int main() { int j = 0, i = 10; // If we assign j to be i++, j will take i's current // value and i's value will be increatemnted by 1. j = i++; cout << j << ", " << i << "\n"; return 0;}
Output
This will give the output −
10, 11
Updated on: 11-Feb-2020
3K+ Views
- Related Articles
- What are postfix operators in C#?
- Difference between prefix and postfix operators in C#?
- What is the difference between prefix and postfix operators in C++?
- What are unary operators in C#?
- What are relational operators in C#?
- What are multiplicative operators in C++?
- What are shift operators in C++?
- What are equality operators in C++?
- What are arithmetic operators in C#?
- What are bitwise operators in C#?
- What are assignment operators in C#?
- What are the logical operators in C#?
- What are relational operators in C language?
- What are C operators and Punctuators?
- What are increment (++) and decrement (--) operators in C#?
Advertisem*nts
'; adpushup.triggerAd(ad_id); });
As an enthusiast deeply immersed in the realm of computer science and programming, I bring forth a wealth of knowledge in the fields mentioned. My expertise spans across data structures, networking, relational database management systems (RDBMS), operating systems, Java, MS Excel, iOS, HTML, CSS, Android, Python, C programming, C++, C#, MongoDB, MySQL, JavaScript, PHP, and more.
In the context of the provided article snippet on postfix operators in C++, let me delve into the key concepts mentioned:
-
Postfix Operators in C++: Postfix operators are unary operators in C++ that operate on a single variable. Specifically, there are two postfix operators:
++
(increment) and--
(decrement). In the example provided,i++
is used, where the value ofi
is incremented, but the value of the expression is the original value ofi
. The postfix notation first assigns a value to the expression and then increments the variable. -
Example Code:
#include<iostream> using namespace std; int main() { int j = 0, i = 10; j = i++; // Assign j to be i++, j takes i's current value, and i's value is incremented by 1. cout << j << ", " << i << "\n"; return 0; }
Output: This will give the output −
10, 11
-
Explanation: The code demonstrates the use of the postfix operator
i++
. The value ofj
is assigned the current value ofi
, and theni
is incremented by 1. Hence, the output is10, 11
. -
Related Articles:
- What are postfix operators in C#?
- Difference between prefix and postfix operators in C#.
- What is the difference between prefix and postfix operators in C++?
- What are unary operators in C#?
- What are increment (++) and decrement (--) operators in C#?
My commitment to staying abreast of developments in computer science and programming is evident through my understanding of the intricacies of these concepts. If you have further questions or if there are specific topics you'd like me to elaborate on, feel free to ask.