İfadeler
Bir ifade, değerlendirilme belirten bir dizi operatör ve onların işlenenlerini ifade eder.
İfadelerin değerlendirilmesi sonuç (ör. 2+2'nin değerlendirilmesi 4 sonucunu üretir) veya çeşitli yan etkiler üretebilir (ör. std::printf("%d",4)'nin değerlendirilmesi standart çıktı üzerinde '4' karakterini yazdırır).
Konu başlıkları |
[düzenle]Genel
- değer kategorileri (lvalue, rvalue, glvalue, prvalue, xvalue) ifadeleri değerlerine göre sınıflandırır
- değerlendirilme sırası parametre ve alt-ifadelerin değerlendirilme sırası ara sonuçların elde edildiği sırayı belirtir
[düzenle]Operatörler
Common operators | ||||||
---|---|---|---|---|---|---|
assignment | increment decrement | arithmetic | logical | comparison | member access | other |
a = b | ++a | +a | !a | a == b | a[b] | a(...) |
Special operators | ||||||
static_cast converts one type to another compatible type |
- operatör öncelikleri operatörlerin parametrelerine bağlanma sırasını tanımlar.
- alternative representations are alternative spellings for some operators
- operator overloading makes it possible to specify the behavior of the operators with user-defined classes.
[düzenle]Conversions
- standard conversions implicit conversions from one type to another
const_cast
conversionstatic_cast
conversiondynamic_cast
conversionreinterpret_cast
conversion- explicit cast conversion using C-style cast notation and functional notation
- user-defined conversion makes it possible to specify conversion from user-defined classes
[düzenle]Memory allocation
- new expression allocates memory dynamically
- delete expression deallocates memory dynamically
[düzenle]Other
- constant expressions can be evaluated at compile time and used in compile-time context (template arguments, array sizes, etc)
sizeof
alignof
typeid
- throw-expression
[düzenle]Primary expressions
The operands of any operator may be other expressions or primary expressions (e.g. in 1+2*3, the operands of operator+ are the subexpression 2*3 and the primary expression 1).
Primary expressions are any of the following:
Any expression in parentheses is also classified as a primary expression: this guarantees that the parentheses have higher precedence than any operator. Parentheses preserve value, type, and value category.
[düzenle]Literals
Literals are the tokens of a C++ program that represent constant values embedded in the source code.
- integer literals are decimal, octal, hexadecimal or binary numbers of integer type.
- character literals are individual characters of type char, char16_t, char32_t, or wchar_t
- floating-point literals are values of type float, double, or longdouble
- string literals are sequences of characters of type constchar[], constchar16_t[], constchar32_t[], or constwchar_t[]
- boolean literals are values of type bool, that is true and false
- nullptr is the pointer literal which specifies a null pointer value (C++11'den beri)
- user-defined literals are constant values of user-specified type (C++11'den beri)
[düzenle]Unevaluated expressions
The operands of the four operators typeid, sizeof, noexcept, and decltype(C++11'den beri) are expressions that are not evaluated (unless they are polymorphic glvalues and are the operands of typeid
), since these operators only query the compile-time properties of their operands. Thus, std::size_t n = sizeof(std::cout<<42); does not perform console output.
The unevaluated operands are considered to be full expressions even though they are syntactically operands in a larger expression (for example, this means that sizeof(T()) requires an accessible | (C++14'den beri) |
The requires-expressions are also unevaluated expressions. | (C++20'den beri) |
[düzenle]Discarded-value expressions
A discarded-value expression is an expression that is used for its side-effects only. The value calculated from such expression is discarded. Such expressions include the full expression of any expression statement, the left-hand argument of the built-in comma operator, or the argument of a cast-expression that casts to the type void.
Array-to-pointer and function-to-pointer conversions are never applied to the value calculated by a discarded-value expression. The lvalue-to-rvalue conversion, however, is applied, but only if the expression is a volatile-qualified glvalue and has one of the following forms (possibly parenthesized)
- id-expression
- array subscript expression
- class member access expression
- indirection
- pointer-to-member operation
- conditional expression where both the second and the third operands are one of these expressions,
- comma expression where the right operand is one of these expressions.
In addition, if the expression is of class type, a volatile copy-constructor is required to initialize the resulting rvalue temporary. | (until C++17) |
If the expression is a prvalue (after any lvalue-to-rvalue conversion that might have taken place), temporary materialization occurs. If the original glvalue is of volatile-qualified class type, a volatile copy-constructor is required to initialize the resulting rvalue temporary. Compilers may issue warnings when an expression other than cast to | (C++17'den beri) |