C Programming Tutorial 31 – Arithmetic Operators

This video is going to discuss the arithmetic operators. Now, we’ve discussed these some already and I’m sure you are familiar with them from math classes you’ve taken so this video is really not going to be that hard or confusing.

The arithmetic operators include the +, -, /, and *. These are all binary operators that need two operands.

The / is called a forward slash. Some people call \ a forward slash and they are wrong! The top of the slash is the reference point, not the bottom. The top is leaning forward, therefore / is called the forward slash.

The * is called an astersk. I like to call it capital 8, but I’m weird.
 
Now, when you have an expression like this:
 
int x = 2 + 3 * 4 / 3 – 2;

First the multiplication and division happens from left to right, whichever comes first. This means that 3 * 4 happens first. The expression could be simplified to 2 + 12 / 3 – 2. The next thing to happen is 12 / 3. The expression could be simplified to 2 + 4 – 2. Next, the addition and subtraction happens, whichever comes first from left to right. So we get 6 – 2 which evaluates to 4.

You may find it more clear if we did this:

int x = 2 + ((3 * 4) / 3) – 2;
 
You can use as many parenthesis as you want and wherever you want, as long as you remember to close any parenthesis you open. They always get evaluated from the inside out. So 3 * 4 happens first, then the result of that gets divided by 3.
 
Now, you can also use parenthesis to force a certain part of the expression to happen first. For example, if we wanted the subtraction to happen first, we could have set it up like this:
 
int x = 2 + 3 * 4 / (3 – 2);
 
Let’s output this and make sure we get the result we expect.
 
Some people choose to use parenthesis for nearly everything because they believe without them it is easier to make mistakes with arithmetic, but this is up to you.
 
Now, I’m going to introduce you to a new operator…
Check out this expression.
 
int y = 5 % 2;
 
Now, I can tell you now that the value of y is going to be 1. Can you figure out what this operator does? We’ll find out in the next video.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support me! http://www.patreon.com/calebcurry

Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter

Donate!: http://bit.ly/DonateCTVM2.

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content: http://CalebCurry.com
Facebook: http://www.facebook.com/CalebTheVideoMaker
Google+: https://plus.google.com/+CalebTheVideoMaker2
Twitter: http://twitter.com/calebCurry

Amazing Web Hosting – http://bit.ly/ccbluehost (The best web hosting for a cheap price!)

Comments

Mustafa Saeed says:

aren’t you going to continue Oracle & SQL server series ???

phoenix says:

GTK tutorial ?

faht fak carl says:

Omg you give so much details, I love it, the best tutorial ever

Mc Mihion says:

Why can’t i remove others dissilkes on yt? xD

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles   Show Cars   Motorbikes   Scooters   Rims & Tires   Luxury BoatsFashion   Sunglasses   Luxury Watches   Luxury Purses   Jeans Wear   High Heels   Perfumes   Jewellery   Cosmetics   Shaving Helpers   Fashion HatsFooding   Chef Club   Fooding Helpers   Coktails & LiquorsSports   Sport Shoes   Fitness & Detox   Golf Gear   Racquets   Diving Equipment   Ski Gear   Snowboards   Surf Boards   Rollers & SkatesEntertainment   DIY Guides   Zik Instruments   Published Books   Music Albums   Cine Movies   Trading Helpers   Make Money   Fishing Equipment   Paintball Supplies   Trading Card Games   Telescopes   Knives   VapesHigh Tech   Flat Screens   Tech Devices   Camera Lenses   Printers   USB Devices   PC Hardware   Network Gear   Cloud Servers   Software Helpers   Programmer Helpers   Mobile Apps   Hearing AidsHome   Home Furniture   Home Appliances   Beddings   Floor Layings   Barbecues   Aquarium Gear   Safe Boxes   Office Supplies   Security Locks   Cleaning ProductsKids   Baby Strollers   Child Car Seats   Remote ControlledTravel   Luggages & Bags   Airlines Seats   Hotel Rooms   Fun Trips   Cruise Ships   Mexico Tours