15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

530<br />

Using Operators<br />

The increment operator replaces the + 1 portion with ++, such as<br />

j = 5;<br />

i = ++j;<br />

In the preceding example, the value of i is j + 1 or 6, and the value of j is<br />

also 6.<br />

If you place the increment operator after the variable, such as<br />

j = 5;<br />

i = j++;<br />

Now the value of i is 5, but the value of j is 6.<br />

The decrement operator works the same way except that it subtracts 1 from<br />

a variable, such as<br />

j = 5;<br />

i = --j;<br />

In the preceding example, the value of i is j - 1 or 4, and the value of j is<br />

also 4.<br />

If you place the decrement operator after the variable, such as<br />

j = 5;<br />

i = j--;<br />

Now the value of i is 5, but the value of j is 4.<br />

Assignment operators<br />

Most <strong>programming</strong> languages use the equal sign to assign values to variables,<br />

such as<br />

i = 59;<br />

However, C/C++ also includes combination assignment and mathematical<br />

operators, as shown in Table 1-6.

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

Saved successfully!

Ooh no, something went wrong!