Global Trend Radar
Web: learn.microsoft.com US web_search 2026-05-01 01:53

前置インクリメントおよびデクリメント演算子

原題: Prefix Increment and Decrement Operators: - learn.microsoft.com

元記事を開く →

分析結果

カテゴリ
AI
重要度
54
トレンドスコア
18
要約
前置インクリメント(++)およびデクリメント(--)演算子は、変数の値を1増加または減少させるために使用されます。これらの演算子は、変数の前に置かれることで、演算が行われた後に新しい値が返されます。これにより、変数の値を即座に変更し、その結果を他の計算に利用することが可能です。プログラミングにおいて、これらの演算子は効率的なコードを書くために重要な役割を果たします。
キーワード
Prefix Increment and Decrement Operators: ++ and -- | Microsoft Learn Table of contents Exit editor mode Ask Learn Ask Learn Reading mode Table of contents Read in English Add Add to plan Edit Copy Markdown Print Note Access to this page requires authorization. You can try signing in or changing directories . Access to this page requires authorization. You can try changing directories . Prefix Increment and Decrement Operators: ++ and -- Feedback Summarize this article for me Syntax ++ unary-expression -- unary-expression Remarks The prefix increment operator ( ++ ) adds one to its operand; this incremented value is the result of the expression. The operand must be an l-value not of type const . The result is an l-value of the same type as the operand. The prefix decrement operator ( -- ) is analogous to the prefix increment operator, except that the operand is decremented by one and the result is this decremented value. Visual Studio 2017 version 15.3 and later (available in /std:c++17 mode and later): The operand of an increment or decrement operator may not be of type bool . Both the prefix and postfix increment and decrement operators affect their operands. The key difference between them is the order in which the increment or decrement takes place in the evaluation of an expression. For more information, see Postfix Increment and Decrement Operators . In the prefix form, the increment or decrement takes place before the value is used in expression evaluation, so the value of the expression is different from the value of the operand. In the postfix form, the increment or decrement takes place after the value is used in expression evaluation, so the value of the expression is the same as the value of the operand. For example, the following program prints " ++i = 6 ": // expre_Increment_and_Decrement_Operators.cpp // compile with: /EHsc #include <iostream> using namespace std; int main() { int i = 5; cout << "++i = " << ++i << endl; } An operand of integral or floating type is incremented or decremented by the integer value 1. The type of the result is the same as the operand type. An operand of pointer type is incremented or decremented by the size of the object it addresses. An incremented pointer points to the next object; a decremented pointer points to the previous object. Because increment and decrement operators have side effects, using expressions with increment or decrement operators in a preprocessor macro can have undesirable results. Consider this example: // expre_Increment_and_Decrement_Operators2.cpp #define max(a,b) ((a)<(b))?(b):(a) int main() { int i = 0, j = 0, k; k = max( ++i, j ); } The macro expands to: k = ((++i)<(j))?(j):(++i); If i is greater than or equal to j or less than j by 1, it will be incremented twice. Note C++ inline functions are preferable to macros in many cases because they eliminate side effects such as those described here, and allow the language to perform more complete type checking. See also Expressions with Unary Operators C++ Built-in Operators, Precedence and Associativity Prefix Increment and Decrement Operators Feedback Was this page helpful? Yes No No Need help with this topic? Want to try using Ask Learn to clarify or guide you through this topic? Ask Learn Ask Learn Suggest a fix? Additional resources Last updated on 2025-08-11 Was this page helpful? Yes No No Need help with this topic? Want to try using Ask Learn to clarify or guide you through this topic? Ask Learn Ask Learn Suggest a fix?

類似記事(ベクトル近傍)