A postfix operator immediately succeeds its operand, as in x! for instance.
Questions tagged [postfix-operator]
177 questions
393
votes
17 answers
Why avoid increment ("++") and decrement ("--") operators in JavaScript?
One of the tips for jslint tool is:
++ and --
The ++ (increment) and -- (decrement)
operators have been known to contribute to bad code by
encouraging excessive trickiness. They
are second only to faulty architecture
in enabling to viruses and…

artlung
- 33,305
- 16
- 69
- 121
59
votes
13 answers
What is the difference between prefix and postfix operators?
The following code prints a value of 9. Why? Here return(i++) will return a value of 11 and due to --i the value should be 10 itself, can anyone explain how this works?
#include
main()
{
int i= fun(10);
printf("%d\n",--i);
}
int…

pradeep
- 607
- 1
- 6
- 3
24
votes
6 answers
Why does the postfix increment operator take a dummy parameter?
Have a look at these function signatures:
class Number {
public:
Number& operator++ (); // prefix ++
Number operator++ (int); // postfix ++
};
Prefix doesn't take any parameter but postfix does. Why? I thought we can recognize them…

Naruto
- 9,476
- 37
- 118
- 201
22
votes
3 answers
What does the postfix "_t" stand for in C?
Possible Duplicate:
What does a type followed by _t (underscore-t) represent?
While typing in my IDE (Xcode), autocomplete pops up already-defined words when I'm partway thru entering some variable name. I occasionally see names that have '_t' at…

willc2
- 38,991
- 25
- 88
- 99
21
votes
5 answers
What is '-1[p]' when p points to an array (of int) index?
Today I stumbled over a C riddle that got a new surprise for me.
I didn't think that -1[p] in the example below would compile, but it did. In fact, x ends up to be -3.
int x;
int array[] = {1, 2, 3};
int *p = &array[1];
x = -1[p];
I…

Erik Stroeken
- 519
- 4
- 16
18
votes
1 answer
overloaded "operator++" returns a non const, and clang-tidy complains
I have just got the following warning from clang-tidy:
overloaded "operator++" returns a non-constant object
instead of a constant object type
https://clang.llvm.org/extra/clang-tidy/checks/cert-dcl21-cpp.html
Unfortunately the link which they…

Ferenc Deak
- 34,348
- 17
- 99
- 167
16
votes
9 answers
i++ less efficient than ++i, how to show this?
I am trying to show by example that the prefix increment is more efficient than the postfix increment.
In theory this makes sense: i++ needs to be able to return the unincremented original value and therefore store it, whereas ++i can return the…

cschol
- 12,799
- 11
- 66
- 80
15
votes
2 answers
What does the dot before a postfix or postcircumfix in Perl 6 mean?
In the Perl doc, there is a section about .postfix/.postcircumfix, it says that
In most cases, a dot may be placed before a postfix or postcircumfix:
my @a;
@a[1, 2, 3];
@a.[1, 2, 3]; # Same
Technically, not a real operator; it's syntax…

chenyf
- 5,048
- 1
- 12
- 35
14
votes
3 answers
Why are Postfix ++/-- categorized as primary Operators in C#?
Currently I'm teaching a class of C++ programmers the basics of the C# language. As we discussed the topic operators I used C# standard categories of primary, unary etc. operators.
One of the attendees felt puzzled, because in the C# standard the…

Nico
- 1,554
- 1
- 23
- 35
13
votes
3 answers
Different results when using increment operator (arr[i++] vs arr[i]; i++;)
I can't get my head around why the code below is not working as expected:
#include
int main() {
int i = 0, size = 9, oneOrZero[] = {1,1,1,1,1,1,1,1,0};
while (i < size && oneOrZero[i++]);
if (i == size) printf("All ones");…

milancodes
- 173
- 1
- 7
12
votes
3 answers
Why does postfix operator++ have higher precedence than prefix operator++?
Defined this way, we can do neither ++x++ nor ++x--. But on the other hand, both (++x)++ and (++x)-- are useful expressions: (++x)++ increments x by two and returns the value "in the middle", while (++x)-- is essentially equivalent to x+1 but…

leftaroundabout
- 117,950
- 5
- 174
- 319
11
votes
4 answers
overloading postfix and prefix operators
please consider following code
#include
using namespace std;
class Digit
{
private:
int m_digit;
public:
Digit(int ndigit=0){
m_digit=ndigit;
}
Digit& operator++();//prefix
Digit&…
user466534
11
votes
9 answers
Precedence of ++ and -- operators in Java
I read from the official tutorial of Java that prefix and postfix ++ -- have different precedences:
postfix: expr++ expr--
unary: ++expr --expr +expr -expr ~ !
Operators
According to the tutorial, shouldn't this
d = 1; System.out.println(d++ +…

zw324
- 26,764
- 16
- 85
- 118
8
votes
4 answers
How to differentiate (when overloading) between prefix and postfix forms of operator++? (C++)
Because I've overloaded the operator++ for an iterator class
template
typename list::iterator& list::iterator::operator++()
{
//stuff
}
But when I try to do
list::iterator IT;
IT++;
I get a warning about there being no…
user98188
7
votes
2 answers
Does Postfix operator really has a higher precedence than prefix?
However It is clearly written in precedence table that postfix operator has higher priority than prefix. But still I have a daubt.
I start with following example:
*ptr++; // evaluate as *(ptr++);
++*ptr; // evaluate as ++(*ptr);
This proves…

A.s. Bhullar
- 2,680
- 2
- 26
- 32