In C, the " " operator is used for numerical addition and string concatenation, while the " " operator is used for variable increment. " " can be used as a postfix or prefix operator. Postfix increment is incremented after returning the result, while prefix increment is incremented before returning the result value.
The difference between neutralization in C
In C, the " " and " " operators have different purposes :
Operator
Operator
Difference summary
Features | Operator | Operator |
---|---|---|
Basic uses | Numerical addition, string concatenation | Variable increment |
One yuan/two yuan | One yuan and two yuan | Only one yuan |
Increment after returning the result | Return the result after incrementing | |
May return a new value or pointer | Return the original value of the variable or after incrementing Value of |
Example
<code class="cpp">// 加法 int sum = 2 + 3; // sum 为 5 // 字符串连接 std::string name = "John" + " Doe"; // name 为 "John Doe" // 一元加法 int count = 1; count++; // count 为 2 // 后缀递增 int value = 5; int result = value++; // result 为 5,value 为 6 // 前缀递增 int score = 10; int newScore = ++score; // newScore 为 11,score 也为 11</code>
The above is the detailed content of The difference between + and ++ in c++. For more information, please follow other related articles on the PHP Chinese website!