- 5paisa
- AdSense
- Android
- Asphalt 8 : Airborne Mod Apk 4.9.1b Unlimited Money
- Battlegrounds Mobile India
- Blogger
- Blogging
- Bug Hunting
- cloud storage
- Cmd
- Damn vulnerable Web Application
- Demat Account
- Difference between
- dj alok
- dj alok in free firefree
- Doodle Army 2 : Mini Militia 5.2.0 Apk + Mod for android
- DVMA
- E-books
- earn Bitcoins
- Ethical hacking tutorials
- Express vpn
- EXPRESSVPN PRO APK 7.12.1
- EXPRESVPN CRACKED APK
- fire dj alok
- Freefire
- Gaming
- Google drive
- Google llc
- gplink
- Groww App
- Health
- helo
- helo mela
- helo app
- Helo app earn paytm
- Helo app full guide
- Helo app invite and earn
- Helo app redeem proof
- Helo app refer and earn
- Helo app unlimited trick
- Helo app withdraw proof
- Helo Mela Offer: Get Rs.2 Free Paytm Cash + Win Upto Rs.10000 Paytm Cash
- helo refer and earn
- How to
- How to combine two Wifi Connections to get a faster Internet
- how to get dj alok for free
- how to get free dj alok
- how to get free dj alok in free fire
- How to install DVWA on Kali Linux 2020.2
- How To Use Light Speed WebCache on Your website
- ICICI Direct
- IOS
- kali linux
- Live streaming
- makeup
- meesho
- Money Earning
- My poems
- Netflix
- Netflix mod
- Netflix premium
- News
- online courses
- Pentesting
- programming
- PUBG
- Puffin Browser Pro 8.3.0.41446 (Full) Apk + Mod for Android
- Puzzles
- Recharge offers
- Refer and Earn
- Reviews
- SEO
- shell Scripting
- Shortlink
- Spotify Music 8.5.57.1164 APK Mega Mod Cracked Latest Android
- stylish name
- Technology
- Tips&Tricks
- Township Mod Apk 7.5.0 Unlimited Money
- Udemy
- Udemy courses
- Udemy free
- Udemy premium
- VClip app download link
- VClip app full details
- VClip app invitation link
- VClip app referral code
- VClip app referral link
- VClip app review
- Web designing
- What is
- WINDOWS
- Wishes
- Wordpress
- World Cricket Championship 2 2.8.9 Apk + Mod (Coins/Unlocked)
- Youtube tricks
- zoom app
- zoom bombing
- zoom call
- Zoom safety tips
WHAT IS OPERATOR PRECEDENCE AND ASSOCIATIVITY
Every C operator has a precedence (priority) associated with it. This precedence is used to determine how an expression involving more than one operator is evaluated. There are different levels of operator precedence and an operator may belong to one of these levels. The operators at the higher level of precedence are evaluated first. The operators in the same level of precedence are evaluated from left to right or from right to left, based on the associativity property of an operator. In the below table we can look at the precedence levels of operators and also the associativity of the operators within the same level. Rank 0 indicates the lowest precedence and Rank 14 indicates highest precedence.
The precedence and associativity of various operators in C are as given below :
An expression is a sequence of operands and operators that reduces to a single value. For example, the expression, 10+5 reduces to the value of 15. Based on the operators and operators used in the expression, they are divided into several types. Some of them are :
1. Integer expressions – expressions which contains integers and operators
2. Real expressions – expressions which contains floating point values and operators
3. Arithmetic expressions – expressions which contain operands and arithmetic operators
4. Mixed mode arithmetic expressions – expressions which contain both integer and real operands
5. Relational expressions – expressions which contain relational operators and operands
6. Logical expressions – expressions which contain logical operators and operands
7. Assignment expressions and so on… – expressions which contain assignment operators and operands
Example 1
Let’s understand the operator precedence and associativity rules with the help of an example. The expression that we consider for this example is :
if(x==10+15&&y<10)
In the above expression, the operators used are: ==,+,&& and <. By looking at the operator precedence table, + operator is at level 4, < operator is at level 6, == operator is at level 7 and && operator is at level 11. So clearly, the + operation is performed first. Then our expression becomes :
if(x==25&&y<10)
Now, since < operator has the next highest precedence, y<10 is evaluated. If we assume value of x is 20 and value of y is 5, then the value of y<10 is true. Then the == operator is evaluated. Since value of x is 20, x==25 evaluates to false. So, our expression becomes :
if(false&&true)
Now, the only operator left is &&. It is evaluated next and the result is false.
Example 2
Let us try to evaluate an arithmetic expression as shown below :
x = a-b/3+c*2-1
Let a = 9, b =12, and c=3. Then our expression becomes :
x = 9-12/3+3*2-1
From the above table, we can see that the * and / operators are having higher precedence than + and – operators. Also, the * and / operators are at the same level of precedence, so we have to apply the associativity rules. Since the associativity rule is left-to-right, we apply the / operator first and the expression evaluates to :
x = 9-4+3*2-1
Next, we apply the * operator and the expression becomes :
x = 9-4+6-1
Next, we apply the first – operator as the – and + operators are at the same level and the associativity rule is from left to right. The expression becomes :
x = 5+6-1
Now, we apply the + operator and the expression become:
x = 11-1
Finally, we apply the – operator and the result is:
x = 10
Take your time to comment on this article.
Also Read
KUMAR JEERU
. I am a Programmer and Pentester. I find and Fix loophole in websites and networks. Connect with me for queries , web developemnt , Scanning and Fixing website Security issues. My company gives special discount for independent entrepreneur , small and Medium size companies. Contact me directly on my face page
Post a Comment
Post a Comment