C: More Operators and Arrays - Bitwise Operators
(Page 2 of 5 )
Though these operators are a bit beyond the scope of this particular article, it is good to know of their existence; otherwise when I teach them to you in a future article, you will have a heart attack and that insurance policy your mom and I just took out on you will pay us handsomely.
Operator | What it Means |
& | For Bitwise AND |
| | For Bitwise OR |
^ | For Bitwise Exclusive |
<< | For Shift left |
>> | For Shift right |
These operators manipulate given data at the bit level, operating on each bit of the data. They cannot be used on floats or doubles.
Well they can, but it won't work. Chump.
Comma Kazi
When we want to link a series of related expressions together, we use the comma operator. The list of expressions is evaluated from left to right and the last expression becomes the value of the expressions combined.
Behold my mighty example:
hercules = (a=5, b=12, a+b);
In the above example, we assign a the value of 5, and b the value of 12. Then we add a and b together, and that value becomes the value of hercules. So in the end, hercules becomes 17.
We will discuss the comma operator more in depth when we cover Loops in a future tutorial.
Does This Variable Make Me Look Fat?
The "size of" operator returns the size of a data type, variable, arrays, constants, and data type qualifiers. It tells you how many bytes the operand takes up in memory. You can also use it to allocate memory to variables when the program executes.
The "size of" operator is a little beyond the scope of this article.
There are other operators in C, such as the pointer operators and selection operators, which we will cover in upcoming episodes.
One last thing regarding operators. When we want to give a part of an equation precedence, we do so by encapsulating it with parentheses(). Consider the following:
5+2*5= 35
5+(2*5)= 15
In the first example, math is performed left to right, result in the answer thirty-five. In the second example however, we give the equation 2*5 precedence by wrapping it in parentheses. This way the program does the multiplication first, then adds 5, resulting in the answer 15.
Next: Arrays >>
More BrainDump Articles
More By James Payne