Simple case of precedence – CSKC
Sign In

Search

Code Learning #CPP#1752    siteicon   siteicon  

Simple case of precedence

The order in which operators are applied on operands in an expression can be understood with this example.

Learning Objectives

  • Learning steps in simple precedence like the arithmetic precedence learnt at school level.

Source Code

TC++ #1752

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

int x=12 – 5 + 12 / 3 * 2;
In general the BODMAS (Bracket, Of, Divide, Multiply, Add, Subtract) precedence as learned in schools apply. But since c++ has a long list of operators, precedence confusions may arise. For time being let us try to solve above with simple rules only.
12-5+12/3*2
12-5+4*2  (Divide applied)
12-5+8 (Multiply applied)
7+8 =15 (Solved left to right when only add subtract are left)
So the output would be 15.

Notes


Suggested Filename(s): precedence.cpp, simpleprecedence.cpp



Share

Created: 17-Dec-2017 00:10 | Updated: 31-Aug-2018 12:30|