80
C++ should be called ++C (sh.itjust.works)
submitted 1 day ago* (last edited 1 day ago) by [email protected] to c/[email protected]

According to syntax postfix increment returns copy of unmodified variable (C++ == C), while prefix increment returns incremented variable (++C == C + 1).

you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 5 points 1 day ago* (last edited 1 day ago)

???

If c = 1, then c++ = 2

#include using namespace std;

int main() {

int i = 10;

cout << i++ << endl;

cout << i << endl;

}

postfix ++ increments the variable.

[-] [email protected] 6 points 1 day ago

Postfix increments variable too, but as a side effect. in your code cout << i++ << endl; prints 10 which means, that i++ returned copy of unincremented i.

[-] [email protected] 0 points 4 hours ago

Yes c++ == c. That's the point Bjarne Stroustrup made. It is the C language but then it's better.

Nowadays they're not completely compatible. But originally it was a preprocessor that created the C equivalent to be compiled. You could write C++ that compiled with a C compiler as long as you didn't use the extra features.

this post was submitted on 20 Sep 2024
80 points (91.7% liked)

Showerthoughts

29247 readers
616 users here now

A "Showerthought" is a simple term used to describe the thoughts that pop into your head while you're doing everyday things like taking a shower, driving, or just daydreaming. The best ones are thoughts that many people can relate to and they find something funny or interesting in regular stuff.

Rules

founded 1 year ago
MODERATORS