1
00:00:00,720 --> 00:00:05,460
Using the comma operator So operators will be covered later in this section.

2
00:00:05,850 --> 00:00:10,620
However, it's useful to introduce the comma operator here.

3
00:00:11,490 --> 00:00:17,070
So you can have a second set of expressions separated by a comma as a single statement.

4
00:00:17,070 --> 00:00:23,100
For example, let's create an example code here to show you how this comma operator works.

5
00:00:23,130 --> 00:00:26,100
Integer A equals nine, for example.

6
00:00:26,100 --> 00:00:27,780
Integer A equals nine.

7
00:00:28,200 --> 00:00:32,490
Integer B equals four.

8
00:00:33,710 --> 00:00:34,240
Integers.

9
00:00:34,340 --> 00:00:39,290
C equals nothing, so it's automatically zero.

10
00:00:39,920 --> 00:00:41,990
So let's see.

11
00:00:42,020 --> 00:00:50,870
Equals E two plus eight and comma operator B plus one.

12
00:00:51,410 --> 00:00:55,610
So as you can see here, we have a slight problem here.

13
00:00:55,610 --> 00:01:04,880
So this code compile and run without problem and the variable C will be assigned with the value of 17.

14
00:01:05,840 --> 00:01:11,060
Let's print it and I will show you what this is.

15
00:01:11,660 --> 00:01:12,890
C here.

16
00:01:12,890 --> 00:01:14,840
And std.

17
00:01:15,960 --> 00:01:18,560
STD endl here.

18
00:01:20,020 --> 00:01:21,780
So let's print this here.

19
00:01:21,790 --> 00:01:31,480
As you can see here, we got 11, so eight plus nine new plus nine, and we will get 11.

20
00:01:31,480 --> 00:01:33,570
But where is our five?

21
00:01:33,580 --> 00:01:38,080
So as you know, four plus one equals.

22
00:01:40,160 --> 00:01:40,940
Equals five.

23
00:01:40,970 --> 00:01:42,800
So here.

24
00:01:42,830 --> 00:01:43,820
17.

25
00:01:44,440 --> 00:01:45,250
And.

26
00:01:46,510 --> 00:01:48,280
Uh, 17 and five.

27
00:01:48,310 --> 00:01:54,430
As you can see here, this 17 and five did not multiply.

28
00:01:54,430 --> 00:01:59,350
So that's because of the the comma operator is not to multiply here.

29
00:01:59,350 --> 00:02:01,780
So I will explain what this comma is.

30
00:02:01,780 --> 00:02:07,570
So the reason is that this is the reason that the comma operator.

31
00:02:08,680 --> 00:02:14,860
Separates the right side of the assignment into two expressions.

32
00:02:16,330 --> 00:02:21,700
Plus one and B plus a, A plus eight and B plus one.

33
00:02:21,700 --> 00:02:30,820
And it uses the value of the first expression to assign C later in this course, we will look at the

34
00:02:30,820 --> 00:02:32,500
operator precedence.

35
00:02:32,530 --> 00:02:43,330
However, it's worth saying here that the comma has the lowest precedence and plus has higher precedence

36
00:02:44,740 --> 00:02:47,320
than equal to sign here.

37
00:02:47,320 --> 00:02:54,580
So the statement is executed in order of the addition to the addition of of the addition.

38
00:02:54,580 --> 00:03:02,430
So the assignment and then the comma operator with the result of B plus one thrown away just as earlier

39
00:03:02,530 --> 00:03:11,560
as you can see we just get 17 from C here so you can change the precedence using the parentheses to

40
00:03:11,560 --> 00:03:12,550
group expressions.

41
00:03:12,550 --> 00:03:16,040
For example, let's.

42
00:03:17,140 --> 00:03:21,520
I mistyped called could have been here as follows.

43
00:03:21,550 --> 00:03:26,570
Let's get into the parentheses and see what happens here.

44
00:03:26,590 --> 00:03:29,290
As you can see here, we got the five.

45
00:03:29,320 --> 00:03:29,860
Now.

46
00:03:30,640 --> 00:03:37,590
And so the result is this statement is variable C assigned to five, B plus one.

47
00:03:37,680 --> 00:03:40,110
And where is our 17 here?

48
00:03:40,110 --> 00:03:46,170
So the reason is that with the comma operator expression are executed from the left to right.

49
00:03:46,170 --> 00:03:50,670
So the value of the group of expression is the type most one.

50
00:03:50,670 --> 00:03:57,150
So there are some cases, for example, in the initialization or loop expression for a for loop where

51
00:03:57,150 --> 00:04:00,020
you will find the comma operator useful.

52
00:04:00,030 --> 00:04:08,670
But as you can see here, even used intentionally, the comma operator produced hard to read code.

53
00:04:09,150 --> 00:04:11,490
So now actually.

54
00:04:12,560 --> 00:04:14,690
Let's end our.

55
00:04:17,720 --> 00:04:25,670
Lecture now and in the next lecture you will learn about your types and variables.
