Ad alanları
Türevler
Eylemler

İfadeler

cppreference.com sitesinden
< cpp‎ | language
 
 
 
 

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 = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b

a[b]
*a
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
?:

Special operators

static_cast converts one type to another compatible type
dynamic_cast converts virtual base class to derived class
const_cast converts type to compatible type with different cv qualifiers
reinterpret_cast converts type to incompatible type
new allocates memory
delete deallocates memory
sizeof queries the size of a type
sizeof... queries the size of a parameter pack(C++11'den beri)
typeid queries the type information of a type
noexcept checks if an expression can throw an exception (C++11'den beri)
alignof queries alignment requirements of a type (C++11'den beri)

[düzenle]Conversions

[düzenle]Memory allocation

[düzenle]Other


[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:

1) Literals (e.g. 2 or "Hello, world")
2) Suitably declared unqualified identifiers (e.g. n or cout)
3) Suitably declared qualified identifiers (e.g. std::string::npos)

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 T::~T)

(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 void discards a value declared [[nodiscard]]

(C++17'den beri)
close