Comma Operator in C
ฝัง
- เผยแพร่เมื่อ 15 ธ.ค. 2024
- C Programming & Data Structures: Comma Operator in C
Topics discussed:
1. What is the Comma Operator?
2. Use of Comma Operator as the separator.
3. Use of Comma Operator as an operator.
4. Precedence of Comma Operator.
5. Examples based on Comma Operator.
6. Homework on Comma Operator.
C Programming Lectures: goo.gl/7Eh2SS
Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
Contribute: www.nesoacademy...
Memberships: bit.ly/2U7YSPI
Books: www.nesoacademy...
Website ► www.nesoacademy...
Forum ► forum.nesoacade...
Facebook ► goo.gl/Nt0PmB
Twitter ► / nesoacademy
Music:
Axol x Alex Skrindo - You [NCS Release]
#CProgrammingByNeso #CProgramming #CommaOperator
Thank you sir for providing c lectures for free. When many coachings are asking hefty amount for teaching the same thing you are providing this for free. Thank you to the creator of neso academy.
Same words from me to sir
shouldn't internet be used for that, free education?
unfortunately no, at least for now
@@opst1704 I mean compared to online classes u pay both for money and the class fee or whatever is that
@@opst1704 let's just say this is a free course, but u provide the internet
this academy will also require money to teach advance c program when entering files😢😢
He ( , ) was underrated,
But u (neso ac.) brought him into lime light!!
Respect!!
ans: 50;
given num = (var=15, var+35), then initially var =15 was evaluated and the second operand becomes var+35 == 15+35 which results 50. now 50 will be printed.
👍👍
@Nadeem Afzal it will not give an error, the answer is 50
@Nadeem Afzal since plus has higher precidence than assignment operator first it evaluates plus expression and assign it to the variable
yeah yr correct
@Nadeem Afzal
nizar@nizar-X540LA:~$ cat try.c
#include
int main(void){
int var;
int num;
num=(var=15,var+35);
printf("%d
",num);
return 0;
}
nizar@nizar-X540LA:~$ ./try
50
nizar@nizar-X540LA:~$
Litreally gold series .
You will pay 3000-4000 rupees in offline coaching classes and then they will teach you with so much minute details .
But Neso is teaching , for free of cost .
Geeksforgeeks for C is good , but they teach theory more .
Hence geeksforgeeks can be used for note making and then simultaneous examples can be studied from here for practical knowledge .
Thank you very much neso .
Also not everyone is comfortable in just reading the GFG articles rather vedios are more engaging than mere reading !!!
@@sohamshinde1258 Read from gfg and watch the videos from neso .
gfg gives very minute details also .
Can we assign address of a register variable to a pointer ?
The answer is no .
So these are some minute details , and if you are not knowing these minute details , then it will cause a problem .
Hence gfg is good for full understanding , visit each and every link , of gfg and read those and make notes .
Also you can watch the videos of neso also , they are also pretty good .
Hmm
Hii what is gfg and how can i use..... Hlp me
@@poornachandra3138 @gfg - Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles .... I prefer notes there.....
The output is : 50.
Thank you so much, sir, for your such kind of efforts. Your explanation is the best for me so far.
How?
@@am_gonnadomeproud
In the num line, the var variable = 15 gets evaluated first, but it is rejected because , is working as a separator and bracket has the highest presidents here . Then Returns variable + 35 to num variable. Var variable has the value 15 stored inside. So num is 15 + 35 = 50. Then num is printed which is 50. Thanks
my logical thinking gets increased through this awesome course
1:10 Yes, can be used as a seperator, not for pointers though, haven't seen a video where you teach pointers yet though so maybe you'll mention it there, it's a pitfall I've seen a lot of people make though so worth mentioning.
example:
int *a, b,c; // Only 'a' is a pointer the rest are ints
int *a, *b, *c; // All are pointers
Output = 50
num = (var=15, var+35),
i.e var =15 (First expression in the bracket and "assignment" operator takes precedence over "comma" operator, hence var is assigned a value of 15)
next:
var+35 = 15+35 i.e 50.
next:
num will be assigned the value of 50 as var=50 (rightmost operand within the bracket)
The output will be 50. Because "," is used as operator and due to which the rightmost operand's value is considered which is var+35. and also var=15 is also evaluated but rejected at last due to this evaluation the var is initialized to 15.
but shouldnt it be var+=35?
@@tyronemiguelarollado1150 same doubt
Never saw the concepts that nesoacademy guy explains in any videos that i've watched .
I really like your way of teaching. I also recommend my friends to watch the videos of Neso Academy. Cordial thanks to you. From Bangladesh.
I'm loving your c programming language series and I suggested it to my classmates. You have done a great 👏 work, thank you sir 😊
50 is the answer because as brackets are present , comma acts as operator. Therefore, initially the first one is evaluated and becomes var+35 which is 50...
Before neco academy:'c' programming is hard to learn
After neco academy :'c' is very simple programming language to learn
All this credits goes to NESO ACADEMY 😊
Yeah , exactly
Thanks!
Thank you from the bottom my heart sir that as due to financial problems i'm not learned c but because of you this happened
Just excellent...much much much more than paid courses...........never found this things about comma operator
may God bless you more
Ans:50
After solving this expression num= (var=15,var+35);
var =15 bcz it simply evaluate the 1st operand and assign the 2nd operand as he explained in the video so num=var+35.
So final ans is num=50
Appreciate for the course sir, people are asking for tons of $ for even the basics and here you are doing it for free. Reccomended to my classmates and my best friends starting C also :D
answer =50
as the brackets are the highest precedence then (var=15,var+35) will be taken to consideration first
as comma is the lowest precendence then assignment of the value 15 will be evaluated var=15 and the addition of 35 will be evaluated later but as we know the compiler ignores the first argument and return the second argument to num
therefore num=50 wich will be printed later.
note : if we erase the brakets num=var=15,var+35 then comma will be a separator and num will get the value 15
Thanks 😊
this is seriously an awesome explanation, i'm enlightened
num= (var = 15, var+35);
1. var =15
2. var+35 which is equal to var = var + 35
3. var = var(which is 15) + 35
4. var = 50
I really impressed your way of teaching sir.I learnt so many new topics in C language by following this channel......
Within brackets assignment operator is used so first var = 15 is executed and then var is added with 35 then with comma operators store 50 in num then num get printed
1 st priority is the bracket, next, = operater have higher precedency than comma operator, so initially var=15 evaluated, then comma operater evaluated, so num=15+35,
So the output is 50
In the last homework question there are 2 operands imside the bracket so the last operand will be calculated but the first operand will evaluated and then rejected..so after evaluation the value is 15 and then var+35=50 after that var value will be rejected and only num value will be printed which is 50
The output is 50. Thanks for providing quality content.tq neso academy
50.
Reson: 3:09
Thank you, Sir
i read many articles without understanding until i watched this video you described with easy to understand definitions next to illustrations, thanks, hope you do more topics on machine learning and computer science, and math
the answer will be 50. the first expression var=15 will evaluted then rejected and then the rightmost value will be printed.
chal chal apna kaam dekh
@@harshitchauhan2531 dimagi halat thk nhi lg rhi tmhari
Awesome explanation 👌👌👌👌👌👌👌👌👌👌👌
Your way in teaching is awesome , thank you
Comments for myself: The comma can be used as an operator. It will return only the rightmost operand in the expression while evaluating the rest of the operands. Comma operator have the least precendence among all operator, hence it will be evaluated last. Comma can be a separator or an operator. With parentheses, you can make it work like an operator. As for the assignment, the answer is 50 because we used parenthesis hence comma will be an operator here. Then, the expressions are evaluated from left to right, and finally the result of the rightmost expression is stored to variable num and printed.
Sir you really are doing an awesome job by providing such good content and that too free .Please keep continuing such great work.
Neso academy is best and all of the faculties are also good.way of teaching really awesome..love u Neso Academy
ans=50 num=(var=15,var+35)
first var=15 then 15+35
The depth n details by jaspreet sir is awesome
Perfect explanation thank you....
Thanks neso for wonderful explanation of c language ❤❤
This channel is just amazing 👍👍
Great effort! May God bless Neso 🥳😍
I am amazed I studied whole C language and I was unaware of these things....*modi accent* main hairaan hoo....
pl name the video in which size of operator is coverd ............
Sir i humble request you . . . That. . . .please upload java and c sharp language videos. . . .or any object oriented programming language videos. . ..
Teaching at it's utmost perfection
Ans of the hw ques is 50 , bracket will open first => num = var = 15 , num = var +15 as , act as seperator therefore both statement asct as differert => num = 50
Sir, you have mentioned there.
Comma simply evaluates the great of the operands and finally reject them.
We got the output hello! 3:30, then where is the question of rejecting sir.
i think you have misunderstood it .
Here reject means that it did not assign the other operand to the variable but executed them.
it only assign the most right operand.
here the first operand printf("%s
","Hello") is executed but not assigned to the variable.
the most right operand 5 is assigned .
Hope your doubt is clear
Funny how after years of programming you forget that "," is an operator and just use it instinctivley
I was surprised a bit, when I realised that. I thought that I would skip over the operators section in these lectures.
The next level of teaching
Addicted to the playlist... It's awesome
_
s1. braces got higher precedence.
s2. inside the braces, "+" got higher precedence. So, var which is 0 by
default added 35.
s3. next turn is of "=" which is inside the braces of course.
s4. they make var = 15.
s5.now the least precedence of ",". So, according to this, it returns 35 to num and
evaluates var = 15.
s6. now the turn is of "=" (outside the braces).
s7. now every operator has done its job so var = 15 and comma will add 15 with 35 and
return it to num. which is 50.is my assumption correct?
Jazakallahu khairan, brother...
thanks sir for this greatfull and important lecture..
Sir ap bhi to kabhi bataya kro ki really me konsa answer sahi hota h
pl name the video in which size of operator is coverd ............
@@anujsharma8938 lec 6
Try on compiler
I will donate to you.. for sure.. when i have enough to return your service... Sir, No harms comes to a goodman either in life or in death...
b)50
🎉🎉🎉 wow great sir ur lecture is wonder ful. thank u so much.for making such a good video for us
int a;
a=(3, 4, 8);
printf("%d", a);
result=8 because...
the first operation comma operator does is a=3;
second is a=4; and
third is a=8;
so, at last the value 8 is stored in variable a.
50.....evaluate and print rightmost
50 will be the Answer!
Initialy first operand will be evaluated, which assign 15 to var variable, then second operand get evaluated, here value of var variable is 15 plus 35 which gives out 50 which will be assigned to num variable and get printed..
😊
Perfect explanation. ❤️❤️❤️💯
Thank you so much. 🙏🏽
Love you Neso Academy.....You are important more than my GF
ans 50
Thank you. great work
The ans is 50 because ( ) has higher precedence than outer =. But again inside ( ) we have two operations and though +
has higher precedence than = they are separated by comma hence according to the rule operations inside ( ) will get evaluated from left to right hence first var=35 then var+15=50
50 is the output
Tq neso academy...gave an uncountable knowledge
Output is 50
Thank you sooo much sir for providing this course.
Thanks so much sir for providing such wonderful series...🙏🙏
Sir plz upload some more programming languages video lectures......
Output :15, Because,in brackets there is also assignment operator , which is having greater precedance than comma operator. So it just evaluate First operand n rejects the nxt one..
Great understanding 👏
There is + too...which has the precedence greater than =
answer will b 50.
num = (var = 15 , var+35);
now, var+35 ;
we know that is already declared var = 15;
so,
15+35 = 50;
therefore output will be 50✅
What a lecture sir, thank you😊
YOUR CHANNEL IS THE 🐐
CAN U TEACH C++ SIR
I read in k&r the programming language book that "the commas that separate function arguments, variables in declarations, etc, are not comma operators, and do not guarantee left to right evaluation" so are they? or are they not?
tanks for all information and i think the right answer is b the output is 50
1:11
1:42
3:37
5:56
7:04
7:52
8:06
the answer of the question is 50
Ans is 50 therotically as well as on compiler
here the answer is 50.
because, here num=(var=15,var+35);
brackets has the highest precedence after that there is assignment operator, so var=15,
then comma acts as a separator not an operator as there was assignment operator before;
so var+35 = 15+35 = 50 so 50 is assigned to num
and finally 50 is printed...................
The output is 50 and thank you neso academy ❤️👍
num=(15,50);
Output:50
Answer for homework problem is 65(i.e., integer value of (A)). As the condition sizeof(var) is true that is 4(other than 0). Is it correct @Neso Academy.
Ans - 50 ☺
1 st value of var becomes 15 and then after executing var+35 var becomes 50 ie: num=(15,50) therefore ans is 50
the answer is 50 .
.bracket has highest precedence then within bracket assignment operator has more precedence then coma.
very nice and clean lecture . I like it
Grateful to you sir 💖💖💖💞
Nice explaination...
output is 50
ans-50 because the first expression evaluated then second becomes 35+15=50
first evaluate the left hand side expression,
then evaluate the right hand side expression,
finally return the result of the evaluation of the right hand side expression.
it doesn't matter what is the precedence inside the bracket, It will simply work as mentioned above.
Listen to Neso Academy carefully, He just said what I mentioned above.
You will get simply 50 as HW answer. Thank You.
Why var = 15 will be evaluated first??
50, num = var + 35 and simplifcation of remainibg part , var =15
Hats off neso academy
Ans : 50
application / program of using comma ?
so the answer will be 50 because as it is written there that var=15 then var +35 and it is all under num so we have the value of var that is 15 then var +35 that is 15+35 = 50 and it is under num so num = 50 that is our output
#include
int main()
{
int a=1010;
a++;
int var=(5,printf("%d",sizeof(a)));
printf("
%d",var);
return 0;
}
output: 4
1(why here 1 is printed after 4 in output?)
Wow nice one 👍
the answer is 50;
explanation: given num = (var=15,var+35),var + 35 = 50;
now 50 will be printed
What is 'enum'?