C Programming Tutorial 36 - Operator Precedence

Share this & earn $10
Caleb Curry
Published at : 02 Jan 2021
11530 views
301
1

You may have heard from math class of this fancy thing called order of operations. We discussed this in a previous video so I'm not going to waste your time by repeating myself, but I am going to look at the same concept from a bigger point of view.

The point of the order of operations is to say which operators happen first and from which direction. For example, we know for the c operators, the multiplication happens first. This order in which operators happen is known as precedence. For example, you can say that multiplication has precedence over addition. And if we have multiple multiplications in one expression, it happens from left to right. The direction of which way a specific operator happens is known as the operator's associativity.

This is a good reference page that lists the C operators, their precedence, and their associativity.
http://en.cppreference.com/w/c/language/operator_precedence

A good example of left associativity is if we do something like this:

int x, y;
x = y = 5;
 
This is valid C and shows that we can declare two variables on one line and also assign values on one line. In general, I try to do things one step at a time, but sometimes you will encounter statements like these.
 
Although either way the result is going to be that x and y are both equal to 5. The order in which this happens is from the left and from the right. First, y = 5 will happen. Next, x = y will happen.
 
If you have two operators on one line, the first thing that happens is the operator with the highest precedence. For example:

int z = 20;
y = 2;
x = -y + z;
 
This could either be evaluated as:
 
x = -(y + z); //x = - 22

or
 
x = (-y) + z; //x = 18
 
The second is the one that will happen according to the operator precedence.

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

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!)
c programmingprogrammingtutorial

ASL Strategies to organize interpreted content  (Voice - Sign) NIC, EIPA prep

ASL Strategies to organize interpreted content (Voice - Sign) NIC, EIPA prep

ROD OF 335 KKSs!! TRANSFORMING 8K TC IN 14.4K in SECONDS and LEVEL 1K OVERKILL!! #TibiaFerumbrinha🧙

ROD OF 335 KKSs!! TRANSFORMING 8K TC IN 14.4K in SECONDS and LEVEL 1K OVERKILL!! #TibiaFerumbrinha🧙

ROTARY LOCKDOWN CHRISTMAS SPECTACULAR VARIETY SHOW

ROTARY LOCKDOWN CHRISTMAS SPECTACULAR VARIETY SHOW

WE'RE GUARANTEED A TITLE ... BUT ITS TIME TO LEAVE LEBRON! - NBA 2K21 MyCAREER #14

WE'RE GUARANTEED A TITLE ... BUT ITS TIME TO LEAVE LEBRON! - NBA 2K21 MyCAREER #14

Service Holder || Chanchal Chowdhury || Prova || Aa Kho Mo Hasan || Brindabon Das || Salauddin Lavlu

Service Holder || Chanchal Chowdhury || Prova || Aa Kho Mo Hasan || Brindabon Das || Salauddin Lavlu

6 Practical Steps to Setting Achievable Goals

6 Practical Steps to Setting Achievable Goals

Vendée Globe 2020-2021 Finish [EN]

Vendée Globe 2020-2021 Finish [EN]

Raiden 레이든 'The Only (Feat. 아이린 of Red Velvet)' MV

Raiden 레이든 'The Only (Feat. 아이린 of Red Velvet)' MV

What is near and far sighted?

What is near and far sighted?

Samsung Galaxy A20 Display screen Replacement

Samsung Galaxy A20 Display screen Replacement

Bee Gees - Jive Talkin' (Official Music Video)

Bee Gees - Jive Talkin' (Official Music Video)

lyta worry

lyta worry

How to DRAW & SHADE a WHIMSICAL Scandinavian Face with Bangs in Copic Markers (Whimsical Women #7)

How to DRAW & SHADE a WHIMSICAL Scandinavian Face with Bangs in Copic Markers (Whimsical Women #7)

Education vs Schooling

Education vs Schooling

Introduction to Permutations (Ordered Selections)

Introduction to Permutations (Ordered Selections)

Bus #7 Backing out of the garage

Bus #7 Backing out of the garage

Aries💘~ Someone Has Some Major Explaining To Do!! (Very Specific Reading!!)

Aries💘~ Someone Has Some Major Explaining To Do!! (Very Specific Reading!!)

Greedy Vs. Wholesome Twitch Streamer

Greedy Vs. Wholesome Twitch Streamer

Italy Street Food. Huge Ribs on Grill, Sausages, Stuffed Sandwiches and more Food

Italy Street Food. Huge Ribs on Grill, Sausages, Stuffed Sandwiches and more Food

Невероятно! Кремль раскрыл секретный план Америки! Вести от 29.12.20

Невероятно! Кремль раскрыл секретный план Америки! Вести от 29.12.20

TIP #019: Always be sure that the pin numbers in schematic are pointing to ...

TIP #019: Always be sure that the pin numbers in schematic are pointing to ...

Young Thug -- Guarantee

Young Thug -- Guarantee

How's Your Memory? Try This Memory Test with a Psychiatrist

How's Your Memory? Try This Memory Test with a Psychiatrist

125th Anniversary of The Johns Hopkins Hospital

125th Anniversary of The Johns Hopkins Hospital

Confidence Level and Margin of Error

Confidence Level and Margin of Error

Erectile Dysfunction Treatment (hindi) || Napunsakta dur karne ke upay || स्तंभन दोष उपचार || 1mg

Erectile Dysfunction Treatment (hindi) || Napunsakta dur karne ke upay || स्तंभन दोष उपचार || 1mg

16 personality factors : rule consciousness

16 personality factors : rule consciousness

Sentence variety

Sentence variety

8 Fast Growing Vegetables You Can Grow at Home in a Hurry

8 Fast Growing Vegetables You Can Grow at Home in a Hurry

Think of What Democrats Would Be Doing Right Now If This Happened to Them

Think of What Democrats Would Be Doing Right Now If This Happened to Them

old enough to understand

old enough to understand

How To Use A Sustain Pedal - Piano Lesson (Pianote)

How To Use A Sustain Pedal - Piano Lesson (Pianote)

'Tomorrow' live in VR

'Tomorrow' live in VR

VERIFY Team Fact-Checks Trump's 'Most Important Speech'

VERIFY Team Fact-Checks Trump's 'Most Important Speech'

CHAMILLIONAIRE-WARN YOU-MAJOR PAIN

CHAMILLIONAIRE-WARN YOU-MAJOR PAIN

Reviewing the Cheapest iPad!

Reviewing the Cheapest iPad!

9 times to ask for a discount

9 times to ask for a discount

They Call Me 'The Man With No Face' | BORN DIFFERENT

They Call Me 'The Man With No Face' | BORN DIFFERENT

Seeing a Video in Actuality for Actualist

Seeing a Video in Actuality for Actualist

Organic Chemistry 1 Final Exam Review

Organic Chemistry 1 Final Exam Review

Can You Hear The Difference Between an Acoustic and Digital Piano

Can You Hear The Difference Between an Acoustic and Digital Piano

Rated K: What 'possessed' student saw after selfie

Rated K: What 'possessed' student saw after selfie

HOW TO LOOK EXPENSIVE ON A BUDGET | 12 TIPS TO ELEVATE YOUR LOOK

HOW TO LOOK EXPENSIVE ON A BUDGET | 12 TIPS TO ELEVATE YOUR LOOK

Why in 2021, YOU Should Commit to EXERCISING/WORKING OUT💪

Why in 2021, YOU Should Commit to EXERCISING/WORKING OUT💪

4 Reasons Why Narcissists Move On So Quickly After The Discard

4 Reasons Why Narcissists Move On So Quickly After The Discard

Expert: Social media to extremism is like oxygen to fire

Expert: Social media to extremism is like oxygen to fire

bottom line - beau’s song

bottom line - beau’s song

Cherry Jam - Anything is Possible

Cherry Jam - Anything is Possible

Trump declares himself young and vibrant

Trump declares himself young and vibrant