Operators Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

prefix increment (++i)

A

i is incremented by 1 and then assigned to a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

postfix increment (i++)

A

i is assigned to a value and then incremented by 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

prefix decrement (–i)

A

i is decremented by 1 and then assigned to a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

postfix decrement (i–)

A

i is assigned to value and then decremented by 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

addition assignment (a += b)

A

a = a + b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

subtraction assignment (a -= b)

A

a = a - b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

multiplication assignment (a *= b)

A

a = a * b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

division assignment (a /= b)

A

a = a / b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

modulo assignment (a %= b)

A

a = a % b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

bitwise AND assignment (a &= b)

A

a = a & b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

bitwise OR assignment (a |= b)

A

a = a | b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

bitwise XOR assignment (a ^= b)

A

a = a ^ b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

bitwise left shift assignment (a

A

a = a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

bitwise right shift assignment ( a&raquo_space;= b)

A

a = a&raquo_space; b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Java ternary conditional

A

result = testCondition ? value1 : value2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

C ternary conditional

A
if (a > b) {
    result = x;
} else {
    result = y;
}

OR

result = a > b ? x : y;

17
Q

logical left shift assignment (a

A

a = a

18
Q

logical right shift assignment (a&raquo_space;>= b)

A

a = a&raquo_space;>b

19
Q

difference between an arithmetic shift and a logical shift?

A

An arithmetic shift is a bitwise operation that shifts all of the bits of its operand; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in. Instead of being filled with all 0s, as in logical shift, when shifting to the right, the leftmost bit (usually the sign bit in signed integer representations) is replicated to fill in all the vacant positions (this is a kind of sign extension).

Unlike an arithmetic shift, a logical shift does not preserve a number’s sign bit or distinguish a number’s exponent from its mantissa; every bit in the operand is simply moved a given number of bit positions, and the vacant bit-positions are filled in, usually with zeros.

20
Q

Subtract two numbers without using arithmetic operators

A
int subtract(int x, int y)
{
    // Iterate till there is no carry
    while (y != 0)
    {
        // borrow contains common set bits of y and unset
        // bits of x
        int borrow = (~x) & y;
        // Subtraction of bits of x and y where at least
        // one of the bits is not set
        x = x ^ y;
        // Borrow is shifted by one so that subtracting it from
        // x gives the required sum
        y = borrow