Operators: Difference between revisions

From Computer Science Wiki
Line 65: Line 65:
|$a === $b|| Identical ||TRUE if $a is equal to $b, and they are of the same type.
|$a === $b|| Identical ||TRUE if $a is equal to $b, and they are of the same type.
|-
|-
|$a != $b|| Not equal|| TRUE if $a is not equal to $b after type juggling.
|$a != $b|| Not equal|| TRUE if $a is not equal to $b after [http://php.net/manual/en/language.types.type-juggling.php type juggling.].
|-
|-
|$a <> $b|| Not equal|| TRUE if $a is not equal to $b after type juggling.
|$a <> $b|| Not equal|| TRUE if $a is not equal to $b after [http://php.net/manual/en/language.types.type-juggling.php type juggling.]
|-
|-
|$a !== $b ||Not identical ||TRUE if $a is not equal to $b, or they are not of the same type.
|$a !== $b ||Not identical ||TRUE if $a is not equal to $b, or they are not of the same type.

Revision as of 08:10, 22 September 2016

Exclamation.png Warning!!!!

Operators are very important. The way the IB wants you to use operators is different than the way you will use them in real life.


Programming basics[1]

An operator is something that takes one or more values (or expressions, in programming jargon) and yields another value (so that the construction itself becomes an expression)[2].

There are many different types of operators, but the ones we primarily concern ourselves with are boldfaced below. If you'd like to learn more about different types of operators in PHP, please click here.

  • Operator Precedence
  • Arithmetic Operators
  • Assignment Operators
  • Bitwise Operators
  • Comparison Operators
  • Error Control Operators
  • Execution Operators
  • Incrementing/Decrementing Operators
  • Logical Operators
  • String Operators
  • Array Operators
  • Type Operators


Arithmetic operators[edit]

An example of some arithmetic operators in PHP can be found below [3].

Example Name Result
+$a Identity Conversion of $a to int or float as appropriate.
-$a Negation Opposite of $a.
$a + $b Addition Sum of $a and $b.
$a - $b Subtraction Difference of $a and $b.
$a * $b Multiplication Product of $a and $b.
$a / $b Division Quotient of $a and $b.
$a % $b Modulus Remainder of $a divided by $b.
$a ** $b Exponentiation Result of raising $a to the $b'th power.

Conditional operators[edit]

An example of some conditional operators in PHP can be found below [4].

Example Name Result
$a == $b Equal TRUE if $a is equal to $b after type juggling.
$a === $b Identical TRUE if $a is equal to $b, and they are of the same type.
$a != $b Not equal TRUE if $a is not equal to $b after type juggling..
$a <> $b Not equal TRUE if $a is not equal to $b after type juggling.
$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type.
$a < $b Less than TRUE if $a is strictly less than $b.
$a > $b Greater than TRUE if $a is strictly greater than $b.
$a <= $b Less than or equal to TRUE if $a is less than or equal to $b.
$a >= $b Greater than or equal to TRUE if $a is greater than or equal to $b.
$a <=> $b Spaceship An integer less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b. Available as of PHP 7.

A video[edit]

This video references the C programming language and scratch, but the ideas about operators are excellent. In the case of conditionals, PHP and C share similar syntax (but not exact).

The way the IB wants you to use operators[edit]

Please know all code submitted to the IB (with the exception of object oriented programming) is in pseudocode. The way we write operators in pseudocode is different than the way we might write them in the real world.

Click here to view a file describing approved notation, including pseudocode This is the approved notation sheet from the IB.

Below is a graphic that is taken from the above PDF file to help you understand how the IB wants operators to look.

Ib operators.png

Standards[edit]

  • Define the terms: variable, constant, operator, object.
  • Define common operators.
  • Analyse the use of variables, constants and operators in algorithms.

See Also[edit]

References[edit]