This is a list of operators in the C and C++programming languages. All the operators listed exist in C++; the column "Included in C", states whether an operator is also present in C. Note that C does not support operator overloading. When not overloaded, for the operators &&, ||, and , (the comma operator), there is a sequence point after the evaluation of the first operand.
C++ also contains the type conversion operators const_cast, static_cast, dynamic_cast, and reinterpret_cast. The formatting of these operators means that their precedence level is unimportant.
Most of the operators available in C and C++ are also available in other C-family languages such as C#, D, Java, Perl, and PHP with the same precedence, associativity, and semantics.
For the purposes of these tables, a, b, and c represent valid values (literals, values from variables, or return value), object names, or lvalues, as appropriate.
R, S and T stand for any type(s), and K for a class type or enumerated type.
All arithmetic operators exist in C and C++ and can be overloaded in C++.
All comparison operators can be overloaded in C++. All logical operators exist in C and C++ and can be overloaded in C++, albeit the overloading of the logical AND and logical OR is discouraged, because as overloaded operators they behave as ordinary function calls, which means that both of their operands are evaluated, so they lose their well-used and expected short-circuit evaluation property..
All bitwise operators exist in C and C++ and can be overloaded in C++. All assignment expressions exist in C and C++ and can be overloaded in C++. For the given operators the semantic of the built-in combined assignment expression a ⊚= b is equivalent to a = a ⊚ b, except that a is evaluated only once. ^The modulus operator works just with integer operands, for floating point numbers a library function must be used instead (like fmod).
^ abcdefghijkRequires iso646.h in C. See C++ operator synonyms. ^About C++20 three-way comparison. ^ abIn the context of iostreams, writers often will refer to << and >> as the "put-to" or "stream insertion" and "get-from" or "stream extraction" operators, respectively. ^ ab According to the C99 standard, the right shift of a negative number is implementation defined. Most implementations, e.g., the GCC, use an arithmetic shift (i.e., sign extension), but a logical shift is possible.
^The return type of operator->() must be a type for which the -> operation can be applied, such as a pointer type. If x is of type C where C overloads operator->(), x->y gets expanded to x.operator->()->y. ^Meyers, Scott (October 1999), "Implementing operator->* for Smart Pointers"(PDF), Dr. Dobb's Journal, Aristeia. ^About C++11 User-defined literals. ^The parentheses are not necessary when taking the size of a value, only when taking the size of a type.
However, they are usually used regardless. ^C++ defines alignof operator, whereas C defines _Alignof. Both operators have the same semantics.
The following is a table that lists the precedence and associativity of all the operators in the C and C++ languages.