Diving Deeper into C(++)

When using C++ one must always remember to declare variables. The declaration of variables is especially important. It’s like how you have to tell the host of a party in advance if you are bringing a plus one or not. In C++ you can declare multiple variables. Some declarations are global, meaning that they are outside of int main() and other declarations are local, meaning that they are inside of int main().

For example:

int number1{0};

  • The word “int” stands for integer, which refers to a positive or negative whole number
  • The phrase “number1” is the name I would call when referring back to my integer while writing the function
  • “{0}” is means that my first integer is initialized to 0. It does not mean that my integer equals 0. Initializing it to 0 allows for answers to be more accurate.

Since we know how to display data on the screen using cout, storing information using cin, and declaring variables both globally and locally, we can now make room for arithmetic.

Operations & Arithmetic Operators:

Addition= +

Subtraction= –

Multiplication= *

Division= /

Remainder= %

Rules of Operator Precedence:

  1. Parentheses are evaluated first.
  2. Multiplication, division, and remainder operations are evaluated next. If there are several multiplication, division and remainder operations in the same equation they are used in order from left to right.
  3. Addition and subtraction are applied last. If there are several of those operations they to will be considered from left to right.

Relational & Equality Operators:

> means greater than

< means less than

>= means greater than or equal to

<=means less than or equal to

== means equal to

!= means not equal to

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s