• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Caleb Curry

Making Money and Investing

  • Home
  • Make Money Online
  • How to Buy Bitcoin
  • Get Started with Real Estate Investing
  • How to Start a Website
  • Courses
    • Full Time Income Online
  • Sponsorship

C Programming Tutorial 36 – Operator Precedence

October 18, 2018 by Caleb Curry Leave a Comment

Did you read the last blog on Assignment Operators? Are you new here? Start at the beginning, Intro to C!

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.

Precedence and Associativity

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. 

https://en.cppreference.com/w/c/language/operator_precedence

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

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:

This could either be evaluated as:

or

The second is the one that will happen according to the operator precedence.

In the next blog we are going to be discussing all of the Strongly Typed Vs Loosely Typed Languages. Check it out!

Filed Under: Uncategorized Tagged With: c programming, operator precedence

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

my face to show my face

My name is Caleb Curry and I started my online business teaching software development and doing digital marketing for brands. Entrepreneurship has changed my life and has allowed me to earn a full time living from anywhere. I now have the freedom and energy to pursue skills and opportunities that I find interesting. This website is all about my journey.

Get my top Python Tips and Tricks

50+ Python Tips and Tricks!

Subscribe to our newsletter to get notes and latest content by email.

    We won't send you spam. Unsubscribe at any time.

    Follow Me!

    • Instagram
    • YouTube

    Recent Posts

    Copyright © 2021 · Genesis Sample on Genesis Framework · WordPress · Log in