C_21 Operators Precedence and Associativity in C | C programming Tutorials

preview_player
Показать описание
In this Video, I have discussed Operators Precedence and Associativity in C Language.

*******************************************

Connect & Contact Me:

*********************************************

More Playlists:

#cprogramming #jennyslectures #programming #clanguage
#operatorsinc
Рекомендации по теме
Комментарии
Автор

--a*(5+b)/2-c++*b
--0*(5+1)/2-(-1)++*1
Firstly we evaluated which is written in bracket
--0*6/2-(-1)++*1
Now we evaluate postfix increment op
--0*6/2+1*1
We write +1 bcz in postfix firsly value assigned then value incremented
After postfix increment we evaluate prefix decrement
-1*6/2+1*1
We know that * and / has same precidence and associativity is from left to right
-6/2+1*1
-3+1*1
We know that +has lower precidence than * then * evaluated first
-3+1
=-2
Hence answer is -2

shivangikumari
Автор

Shortcut to remember the operator precedence table in C…
Use PUMA' S REBL TAC. ( spell "REBL" as if "REBEL").

(Note: all operators with associativity not specified is left to right).

P - Primary

U - Unary

M - Multiplicative

A - Additive

S- Shift

R- Relational

E- Equality

B- BitWise ( & > ^ > |)

L- Logical ( logical && > logical ||)

and the last three operators are

T- Ternary

A- Assignment

C- Comma

If you need a shortcut for Assosiativity then "AUTo rides in the right side", meaning Assignment, Unary and Ternary operators are Right to Left, O is added for completion)

BodhiiDharma
Автор

Ans = -2

- -a * (5+b) / 2 - c++ * b
- -a * 6 / 2 - - 1 * b (#(), ++, #)
- 1 * 6 / 2 +1 * b (#- -, -, # )
- 3 + 1 (#*, /, *#)
- 2 (#+#)
Operation done on the previous line is commented with # inside the bracket in the new line, in other of operation precedence and separate by non-computing commas.
I didn’t use compiler anyways, but you are free to point out mistakes if found😅

Dr._Aniekan_udo
Автор

Q . --a * (5 + b) / 2 - c++ * b
given a = 0,  b = 1,  c = -1;

ans = -2
explaination-
firsty bracket will be evaluated
so it will give 6
now evaluate --a, it will give -1 since we are pre decrementing 0
now, -1*6 = -6
now -6/2=-3
then -3 - (-1)*b(due to post fix the value of c will remain same )
will give -3 +1*1(since b is given as 1)
hence -3+1=-2 ans

aayushthakur
Автор

Mam ur DS playlist really helped me a lot for exam prep... please make a playlist for Computer architecture also mam... the subject sounds so vague pl help mam... 🙏🙂

nithiya
Автор

Your work is awesome Mama. Your courses of the C language are the best I found on the internet.

herteert
Автор

Mam your videos is easily understandable for me on YouTube platform... Thank you mam for this course🙏

sumitkhursange
Автор

You're really good at explaining things clearly. Good job.

whathuh
Автор

--a will decrement the value of a by 1 and return the new value (-1).
5+b will add 5 to the value of b (which is 1) and return 6.
--a*(5+b) will multiply the result of step 2 by the result of step 1, which gives -6.
/2 will divide the result of step 3 by 2, which gives -3.
c++ will return the current value of c (-1) and then increment it by 1 (to become 0).
c++*b will multiply the result of step 5 by the current value of b (which is 1), which gives 0.
-3-0 will subtract the result of step 6 from the result of step 4, which gives -3.
Therefore, the output of the expression --a*(5+b)/2-c++*b will be -3.

susova
Автор

Waiting from last 5 days.. Happy to see you in my notification 🙂🙂

BITPrateektrivedi
Автор

11:03 #include <stdio.h>
int main()
{
int a=0, b=1, c=-1;

printf("%d", --a*(5+b)/2-c++*b);
return 0;
}
output: -2
working: --a*(5+b)/2-c++*b => -1*6/2+1*1 => -3+1 => -2

fatima
Автор

teaching "extraordinary, fanstatic and mind blowing mam salute mam😇"

yeshwanthrajsp
Автор

do we have to learn this???to solve, but how will i learn such a big table? any short trick? like bodmas or something?

Pramiti_Choudhury
Автор

Mam ur teaching is marvelous this is what a beginner expects

saibalam
Автор

Big thanks to you ma'am, what a smoothness and how u can transmit ur knowledge is just amazing 👏 👌 ❤

emiliarose
Автор

Excellent teaching mam, no words for your teaching

tusharsonawane
Автор

Welcome Back and HnewY 2021 Lecturer Jenny, wish you higher advancement in this year and I promise you to be a good programer because of you.
Step by step any thing is possible

hadieudonne
Автор

int a=0, b=1, c=-1;
- -a * (5+b)/2 - c+ + * ['/ ' is higher precedence than '*']
-1 * 3 - -1 * [value of a will increment first, c is now incremented to 0{-1+1=0}]
-3 - have higher precedence value than '-']
-3 + 1 = -2 ( output)

hulkcochulk
Автор

Compiler Answer : -2
but what i understood from your lecture:
int a=0, b=1, c=-1;
int k= --a *(5+b)/2-c++*b;
--a *6/2-c++*b
--a *6/2-0*b
-1 *6/2-0*b
-6/2-0*1
-3-0*1
-3-0
-3
tell me where i am wrong??

MINHAJ_MJ
Автор

I just watched your previous videos of many months before and you know what you have become chubby and cute from South India ❤️❤️🔥

chaitanyapaidi