Structure: Arithmetic Operators Flashcards

1
Q

This assigns a value to a variable

A

= Assignment operator (single equal sign)

Example

int sensVal; // declare an integer variable named sensVal
sensVal = analogRead(0); // store the (digitized) input voltage at analog pin 0 in SensVal

”=” This assigns a value

”==” This is the equal sign and checks to see if two values are equivalent.

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

These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an int with the value 32,767 gives -32,768). If the operands are of different types, the “larger” type is used for the calculation.

A

Addition(+), Subtraction(-), Multiplication(*), Division(/)

Example

x=x+5

y=y-1

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

Calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array).

A

% (or modulo)

Syntax

result = dividend % divisor

Example

x = 7 % 5; // x now contains 2
x = 9 % 5; // x now contains 4
x = 5 % 5; // x now contains 0
x = 4 % 5; // x now contains 4

Modulo does not work on floats

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