Tuesday, 8 January 2013

Bitwise Operators ( &, |, ^, ~, <<, >> )

Bitwise operators modify variables considering the bit patterns that represent the values they store.


Explicit type casting operator

Type casting operators allow you to convert a datum of a given type to another. There are several ways to do this
in C++. The simplest one, which has been inherited from the C language, is to precede the expression to be
converted by the new type enclosed between parentheses (()):



The previous code converts the float number 3.14to an integer value (3), the remainder is lost. Here, the
typecasting operator was (int). Another way to do the same thing in C++ is using the functional notation:
preceding the expression to be converted by the type and enclosing the expression between parentheses:



Both ways of type casting are valid in C++.

size of ()
This operator accepts one parameter, which can be either a type or a variable itself and returns the size in bytes of
that type or object:


This will assign the value 1to a because char is a one-byte long type.
The value returned by size of is a constant, so it is always determined before program execution.


Other operators
Later in these tutorials, we will see a few more operators, like the ones referring to pointers or the specifics for
object-oriented programming. Each one is treated in its respective section.

No comments:

Post a Comment