### web application

# detailed explanation of operators used in programming

## detailed explanation of operators used in programming

Understanding Expression Operators

=

syntax:

z=x;

Assignment operator (Right associative). Assigns the value of x to the L-value

z. Note that the data type of z must match the data type of x, and cannot be

null.

+=

x += y

Addition assignment operator (Right associative). Adds the value of y to

the original value of x and then reassigns the new value to x. See + for

additional information. x and y cannot be null.

| x | y

Bitwise OR operator. ORs each bit in x with the corresponding bit in y so

that the result bit is set to 1 if at least one of the bits is set to 1. This operator

is not valid for types Long or Integer.

^ x ^ y

Bitwise exclusive OR operator. Exclusive ORs each bit in x with the

corresponding bit in y so that the result bit is set to 1 if exactly one of the bits

is set to 1 and the other bit is set to 0. Assigns the result of the exclusive OR

operation to x.

x++

++x

Increment operator. Adds 1 to the value of x, a variable of a numeric type.

If prefixed (++x), the expression evaluates to the value of x after the increment.

++

If postfixed (x++), the expression evaluates to the value of x before the

increment.

x–

–x

—

Decrement operator. Subtracts 1 from the value of x, a variable of a numeric

type. If prefixed (–x), the expression evaluates to the value of x after the

decrement. If postfixed (x–), the expression evaluates to the value of x before

the decrement.

& x & y

Bitwise AND operator. ANDs each bit in x with the corresponding bit in y

so that the result bit is set to 1 if both of the bits are set to 1. This operator

is not valid for types Long or Integer.

– x – y

Subtraction operator. Subtracts the value of y from the value of x according

to the following rules:

If x and y are Integers or Doubles, subtracts the value of y from the value

of x. If a Double is used, the result is a Double.

If x is a Date and y is an Integer, returns a new Date that is decremented

by the specified number of days.

If x is a Datetime and y is an Integer or Double, returns a new Date that

is decremented by the specified number of days, with the fractional portion

corresponding to a portion of a day.

* x * y

Multiplication operator. Multiplies x, an Integer or Double, with y, another

Integer or Double. Note that if a double is used, the result is a Double.

/ x / y

Division operator. Divides x, an Integer or Double, by y, another Integer or

Double. Note that if a double is used, the result is a Double.

! !x

Logical complement operator. Inverts the value of a Boolean, so that true

becomes false, and false becomes true.

Unary negation operator. Multiplies the value of x, an Integer or Double,

by -1. Note that the positive equivalent + is also syntactically valid, but does

not have a mathematical effect.

*= x *= y

Multiplication assignment operator (Right associative). Multiplies the value

of y with the original value of x and then reassigns the new value to x. Note

that x and y must be Integers or Doubles, or a combination. x and y cannot

be null.

-= x -= y

Subtraction assignment operator (Right associative). Subtracts the value of

y from the original value of x and then reassigns the new value to x. Note

that x and y must be Integers or Doubles, or a combination. x and y cannot

be null.

/= x /= y

Division assignment operator (Right associative). Divides the original value

of x with the value of y and then reassigns the new value to x. Note that x

and y must be Integers or Doubles, or a combination. x and y cannot be

null.

|= x |= y

OR assignment operator (Right associative). If x, a Boolean, and y, a Boolean,

are both false, then x remains false. Otherwise, x is assigned the value of true.

This operator exhibits “short-circuiting” behavior, which means y is

evaluated only if x is false.

x and y cannot be null.

&= x &= y

AND assignment operator (Right associative). If x, a Boolean, and y, a

Boolean, are both true, then x remains true. Otherwise, x is assigned the value

of false. This operator exhibits “short-circuiting” behavior, which means y is

evaluated only if x is true.

>>= x >>= y

Bitwise shift right signed assignment operator. Shifts each bit in x to the

right by y bits so that the low order bits are lost, and the new left bits are set

to 0 for positive values of y and 1 for negative values of y. This value is then

reassigned to x.

>>>= x >>>= y

Bitwise shift right unsigned assignment operator. Shifts each bit in x to the

right by y bits so that the low order bits are lost, and the new left bits are set

to 0 for all values of y. This value is then reassigned to x.

Ternary operator (Right associative). This operator acts as a short-hand for

if-then-else statements. If x, a Boolean, is true, y is the result. Otherwise z

is the result. Note that x cannot be null. ? : x ? y : z

&& x && y

AND logical operator (Left associative). If x, a Boolean, and y, a Boolean,

are both true, then the expression evaluates to true. Otherwise the expression

evaluates to false.

&& has precedence over ||

This operator exhibits “short-circuiting” behavior, which means y is

evaluated only if x is true.

x and y cannot be null.

OR logical operator (Left associative). If x, a Boolean, and y, a Boolean, are

both false, then the expression evaluates to false. Otherwise the expression

evaluates to true.

|| x || y

<<= x <<= y

x and y cannot be null.

Bitwise shift left assignment operator. Shifts each bit in x to the left by y

bits so that the high order bits are lost, and the new right bits are set to 0.

This value is then reassigned to x.

== x == y

Equality operator. If the value of x equals the value of y, the expression

evaluates to true. Otherwise, the expression evaluates to false.

Unlike Java, == in Apex compares object value equality, not reference

equality, except for user-defined types.

<= x <= y

- The comparison of any two values can never result in null.

- If x or y equal null and are Integers, Doubles, Dates, or Datetimes, the

expression is false. - A non-null String or ID value is always greater than a null value.
- If x and y are IDs, they must reference the same type of object. Otherwise,

a runtime error results. - The comparison of two strings is performed according to the locale of the

context user.

Less than or equal to operator. If x is less than or equal to y, the expression

evaluates to true. Otherwise, the expression evaluates to false.

>= x >= y

The comparison of two strings is performed according to the locale of the

context user.

Greater than or equal to operator. If x is greater than or equal to y, the

expression evaluates to true. Otherwise, the expression evaluates to false

- If x or y is an ID and the other value is a String, the String value is

validated and treated as an ID.

x and y cannot be Booleans. - If x or y equal null and are Integers, Doubles, Dates, or Datetimes, the

expression is false. - If x and y are IDs, they must reference the same type of object. Otherwise,

a runtime error results. - A non-null String or ID value is always greater than a null value.

!= x != y

The comparison of two strings is performed according to the locale of the context user.

Inequality operator. If the value of x does not equal the value of y, the

expression evaluates to true. Otherwise, the expression evaluates to false.

Unlike Java, != in Apex compares object value equality, not reference

equality, except for user-defined types.

!== x !== y

The comparison of any two values can never result in null.

Exact inequality operator. If x and y do not reference the exact same location

in memory, the expression evaluates to true. Otherwise, the expression evaluates

to false.

*<< x << y Bitwise shift left operator. Shifts each bit in x to the left by y bits so that the high order bits are lost, and the new right bits are set to 0.*

>> x >> y

Bitwise shift right signed operator. Shifts each bit in x to the right by y bits

so that the low order bits are lost, and the new left bits are set to 0 for positive

values of y and 1 for negative values of y.

>>> x >>> y

Bitwise shift right unsigned operator. Shifts each bit in x to the right by y

bits so that the low order bits are lost, and the new left bits are set to 0 for all

values of y.

For more go to Click here