answersLogoWhite

0

What does C plus C mean?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

In terms of the C++ programming language itself, C++ literally means "the successor to C".

In terms of the operator, operator++ is the increment operator. It has two forms: prefix (++c) and postfix (c++). Both do exactly the same thing and are effectively shorthand for the more verbose c = c + 1 or the more concise c += 1. The difference between the the prefix and postfix versions is in their evaluation. ++c will evaluate to c + 1 while c++ evaluates to c (the value of before the increment). However, the evaluations are only of importance when used in compound expressions:

int a, b, c = 42;

a = c++; // a==42, c==43

b = ++c; // b==44, c==44

Where the evaluation is of no importance, we can use either form. However, for user-defined types, the postfix operator usually incurs an overhead. This can be demonstrated by the following minimal example:

struct foo {

int i;

foo& operator++ () { // prefix increment

++i; // increment this->i

return *this; // return the incremented object

}

foo& operator++ (int) { // postfix increment

foo f {*this}; // copy this object

++i; // increment this->i

return f; // return the pre-incremented object

}

// ...

};

Note that in both cases, the object itself is incremented, the only difference is in what value is returned to the caller (the newly incremented object or the original non-incremented object). However, because postfix increment requires that we copy the original value, we incur an overhead. The more complex the object, the greater that overhead will be.

Built-in types do not suffer the copy overhead because the copy can be factored away by the compiler. Even so, it's a good idea to get into the habit of using prefix increment for built-in types unless you have good reason to use postfix increment. Similarly, it is usually a good idea to omit the postfix operator from user-defined classes unless we have good reason to provide it.

Note that the postfix operator has an unused int argument in order to differentiate it from the prefix operator. The way to remember which is which is that the prefix operator has no argument, which is in common with all the other unary member operators. The postfix operator is the anomaly, thus it gets the dummy argument.

The prefix and postfix decrement operators (operator--) work in a similar way, except they decrement the operand rather than increment it.

User Avatar

Nikko Cormier

Lvl 10
1y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

In terms of the C++ programming language itself, C++ literally means "the successor to C".

In terms of the operator, operator++ is the increment operator. It has two forms: prefix (++c) and postfix (c++). Both do exactly the same thing and are effectively shorthand for the more verbose c = c + 1 or the more concise c += 1. The difference between the the prefix and postfix versions is in their evaluation. ++c will evaluate to c + 1 while c++ evaluates to c (the value of before the increment). However, the evaluations are only of importance when used in compound expressions:

int a, b, c = 42;

a = c++; // a==42, c==43

b = ++c; // b==44, c==44

Where the evaluation is of no importance, we can use either form. However, for user-defined types, the postfix operator usually incurs an overhead. This can be demonstrated by the following minimal example:

struct foo {

int i;

foo& operator++ () { // prefix increment

++i; // increment this->i

return *this; // return the incremented object

}

foo& operator++ (int) { // postfix increment

foo f {*this}; // copy this object

++i; // increment this->i

return f; // return the pre-incremented object

}

// ...

};

Note that in both cases, the object itself is incremented, the only difference is in what value is returned to the caller (the newly incremented object or the original non-incremented object). However, because postfix increment requires that we copy the original value, we incur an overhead. The more complex the object, the greater that overhead will be.

Built-in types do not suffer the copy overhead because the copy can be factored away by the compiler. Even so, it's a good idea to get into the habit of using prefix increment for built-in types unless you have good reason to use postfix increment. Similarly, it is usually a good idea to omit the postfix operator from user-defined classes unless we have good reason to provide it.

Note that the postfix operator has an unused int argument in order to differentiate it from the prefix operator. The way to remember which is which is that the prefix operator has no argument, which is in common with all the other unary member operators. The postfix operator is the anomaly, thus it gets the dummy argument.

The prefix and postfix decrement operators (operator--) work in a similar way, except they decrement the operand rather than increment it.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

2C

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does C plus C mean?
Write your answer...
Submit
Still have questions?
magnify glass
imp