There are many types of operators. There are those who drive
cars, those who perform surgery, those who run casinos, and so on. We don't care
about them, however (at least not for the purposes of this primer!) On the other
hand, we care a lot about those that add or subtract things from each other, and
in other ways manipulate one thing with another. I'm talking about the operators
languages near and dear to a web developer's heart!
Since operators are so fundamental to the work of programming languages, it is important to understand the types of operator that there are, and their place in a language. Understanding fundamental aspects of language structure makes it simpler to get to know a language you are seeing for the first time. That being so, a little clarification couldn't hurt. I don't intend to provide a comprehensive list of either the types of operator or of the operators themselves, but rather to provide a basic understanding of the concepts involved.
In a computer language it's the operators that tell the computer what to do. If you want to add one to one to get a result, you would tell the computer "result equals one plus one". In this example there are two type of operator at work. "Plus" is an arithmetic operator that says to add the two numbers either side of itself together. "Equals" is an operator that says to assign the value of the answer to "result".
Not all types of operator are present, or implemented, in every language. Perl, for example, has a few special groups of operators that are peculiar to Perl. Common to most programming languages, and certainly to those that I have mentioned here, are arithmetic, assignment, relational and logical.
"Add" adds one number to another, meaning that is operates on two numbers, or has two operands. Operators with two operands are called "binary" operators. Those with one operand are called unary, and those with three are called ternary. I don't know of any operators with more than three operands, but they might exist in some language.
While subtract is a binary operator, there is also a unary variation. In its unary form, minus is used to define a negative number, "-1" for example. Exponentiation refers to raising a number to a power. For example (in Perl) 2**4 is equivalent to 2*2*2*2 which yields 16 (2 to the fourth power). Modulus (a.k.a. Modulo) returns the remainder after dividing the first operand by the second operand. For example -- result = 7 modulus 3 -- would give a value of 1 in result.
Assignment operands direct a value into a data item. If our examples above we have shown "equals" as an assignment operator. Most languages these days, including the three previously mentioned, assign from right to left. That is, in the arrangement "op1 = op2" the value already in op2 is assigned to op1, replacing its value. There are still some languages, however, that assign from left to right. Cobol is one such, as in "move op1 to op2" or "add 1 to 1 giving result". By the way, in case you think Cobol is dead, it's worth remembering that it is estimated that there are still more lines of Cobol code in use today than any other language. Of course, we don't really care very much because it's (probably) never used for web site development!
Hopefully, this explanation of this part of computer language structure will help you to operate on your own!
IT Solutions Builder TOP IT RESOURCES TO MOVE YOUR BUSINESS FORWARD
Which topic are you interested in?
What is your company size?
What is your job title?
What is your job function?
Searching our resource database to find your matches...