12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Gett<strong>in</strong>g Your Feet Wet<br />

Operator Description Example<br />

Unary Operators<br />

* Indirection operator <strong>in</strong>t x = *y;<br />

& Address of operator <strong>in</strong>t* x = &y;<br />

~ Bitwise NOT x &= ~0x02;<br />

! Logical NOT if (!valid) {...}<br />

++ Increment operator x++; (same as x = x + 1;)<br />

-- Decrement operator x--;<br />

Class and Structure Operators<br />

:: Scope resolution MyClass::SomeFunction();<br />

-> Indirect membership myClass->SomeFunction();<br />

. Direct membership myClass.SomeFunction();<br />

As you can see, the list of operators is a bit overwhelm<strong>in</strong>g, so don’t worry about try<strong>in</strong>g to<br />

memorize each one. As you work with <strong>C++</strong> you will gradually learn how to use all of the<br />

operators.<br />

It should be noted that <strong>in</strong> some cases an operator can be used either pre-<strong>in</strong>crement (++x) or<br />

post-<strong>in</strong>crement (x++). A pre-<strong>in</strong>crement operator tells the compiler, “Increment the variable’s<br />

value and then use the variable.” A post-<strong>in</strong>crement operator tells the compiler, “Use the<br />

variable first and then <strong>in</strong>crement its value.” For example, this code<br />

<strong>in</strong>t x = 10;<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!