C Programming Tutorial 31 - Arithmetic Operators

submitted by mkenny400 on 03/19/18 1

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! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×