Using the comma operator So operators will be covered later in this section.
However, it's useful to introduce the comma operator here.
So you can have a second set of expressions separated by a comma as a single statement.
For example, let's create an example code here to show you how this comma operator works.
Integer A equals nine, for example.
Integer A equals nine.
Integer B equals four.
Integers.
C equals nothing, so it's automatically zero.
So let's see.
Equals E two plus eight and comma operator B plus one.
So as you can see here, we have a slight problem here.
So this code compile and run without problem and the variable C will be assigned with the value of 17.
Let's print it and I will show you what this is.
C here.
And std.
STD endl here.
So let's print this here.
As you can see here, we got 11, so eight plus nine new plus nine, and we will get 11.
But where is our five?
So as you know, four plus one equals.
Equals five.
So here.
17.
And.
Uh, 17 and five.
As you can see here, this 17 and five did not multiply.
So that's because of the the comma operator is not to multiply here.
So I will explain what this comma is.
So the reason is that this is the reason that the comma operator.
Separates the right side of the assignment into two expressions.
Plus one and B plus a, A plus eight and B plus one.
And it uses the value of the first expression to assign C later in this course, we will look at the
operator precedence.
However, it's worth saying here that the comma has the lowest precedence and plus has higher precedence
than equal to sign here.
So the statement is executed in order of the addition to the addition of of the addition.
So the assignment and then the comma operator with the result of B plus one thrown away just as earlier
as you can see we just get 17 from C here so you can change the precedence using the parentheses to
group expressions.
For example, let's.
I mistyped called could have been here as follows.
Let's get into the parentheses and see what happens here.
As you can see here, we got the five.
Now.
And so the result is this statement is variable C assigned to five, B plus one.
And where is our 17 here?
So the reason is that with the comma operator expression are executed from the left to right.
So the value of the group of expression is the type most one.
So there are some cases, for example, in the initialization or loop expression for a for loop where
you will find the comma operator useful.
But as you can see here, even used intentionally, the comma operator produced hard to read code.
So now actually.
Let's end our.
Lecture now and in the next lecture you will learn about your types and variables.