
OperatorsC++ uses infix operators. These are simply parsed as you would expect. You can also use parenthesis to make sure about the order of precidence. There are three main types of operators. Boolean, aritmetic, and binary. There are also the address and dereference operators which we just discussed for pointers.Boolean are simple, they all return one or zero depending on if they are true or false respectively. They also cast properly to the bool type. They are || for or, and && for and. The comparisons to get a binary result are < > <= >= == and !=. Note that the boolean comparison == operator is NOT the same as the assignment = operator. Arithmitic operators are * / - and +. Note that - can be either a unary or regular operation. All of the operations are strongly typed, however this is only important for division. If you are dividing two integers, you are doing integer division. This means that the computer will truncate the result. This is obviously not what you always want, so be sure to cast up to the correct type before doing division. There are more arithitic operators as well, such as the assignment operator =, and a bunch a manipulative operators. += -= *= /= ++ and --. These allow you to change the value of the variable without using the variable twice. The following are all equivilent: x = x - 1; x -= 1; x--;You get the idea. If you want to know more about these you can look them up, but they are pretty simple, and not all that useful.
Function UseFunctions often return a value. You can then use this value in an expression; for example, you can set the value of a variable with the return value of a function. Since C++ is strongly typed, you need to have the variable be the same type as the return type and all of the things you are passing the function be the correct type as well. Here is an example of the above function being called:// using the add function int theResult = 0; int a = 10, b = 20; theResult = add(a,b); // theResult is now 30 |