File size: 21,486 Bytes
78b4844 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 | 1
00:00:00,000 --> 00:00:03,000
(piano music)
2
00:00:03,000 --> 00:00:05,000
-: In this video, let's talk about operators.
3
00:00:05,000 --> 00:00:06,000
That's right.
4
00:00:06,000 --> 00:00:08,000
You can perform operations on different values.
5
00:00:08,000 --> 00:00:09,000
In fact, we have done that before,
6
00:00:09,000 --> 00:00:13,000
but let's expand the examples and more operators.
7
00:00:13,000 --> 00:00:15,000
So, basically we can add two numbers,
8
00:00:15,000 --> 00:00:16,000
we can subtract two numbers,
9
00:00:16,000 --> 00:00:17,000
we can divide two numbers,
10
00:00:17,000 --> 00:00:19,000
we can multiply two numbers
11
00:00:19,000 --> 00:00:21,000
and also we can perform an operation,
12
00:00:21,000 --> 00:00:25,000
so that you will get a remainder of an operation.
13
00:00:25,000 --> 00:00:26,000
Okay, so when you divide a number
14
00:00:26,000 --> 00:00:29,000
and if you only want a remainder, we can do that as well.
15
00:00:29,000 --> 00:00:32,000
So, let me show you those things with code here.
16
00:00:32,000 --> 00:00:33,000
So, what I will do now is first of all,
17
00:00:33,000 --> 00:00:34,000
let's create two variables
18
00:00:34,000 --> 00:00:36,000
and of course we can name any variable name.
19
00:00:36,000 --> 00:00:39,000
Let's go with integer num1,
20
00:00:39,000 --> 00:00:41,000
and the value, it will have, let's say seven.
21
00:00:41,000 --> 00:00:43,000
And then let's have one more variable here,
22
00:00:43,000 --> 00:00:46,000
which is, let's say five, num2 is five.
23
00:00:46,000 --> 00:00:48,000
And then I can perform some operation
24
00:00:48,000 --> 00:00:51,000
and I can save that operation in a result.
25
00:00:51,000 --> 00:00:54,000
So let's say if you want to add two numbers, we can do that.
26
00:00:54,000 --> 00:00:56,000
We can save the output in result,
27
00:00:56,000 --> 00:00:58,000
and then to perform the operation,
28
00:00:58,000 --> 00:00:59,000
we can use a plus operator.
29
00:00:59,000 --> 00:01:02,000
That's right, we can actually use a plus operator
30
00:01:02,000 --> 00:01:03,000
to add two numbers.
31
00:01:03,000 --> 00:01:05,000
And then once you have done that,
32
00:01:05,000 --> 00:01:06,000
we can simply come back here.
33
00:01:06,000 --> 00:01:09,000
We can say system dot O, dot print, Ellen,
34
00:01:09,000 --> 00:01:11,000
and here we can print the result
35
00:01:11,000 --> 00:01:13,000
and just to see if it is working.
36
00:01:13,000 --> 00:01:14,000
And as we discussed before,
37
00:01:14,000 --> 00:01:16,000
this is not a good way of running a code.
38
00:01:16,000 --> 00:01:18,000
You have to first compile the code, then run.
39
00:01:18,000 --> 00:01:22,000
But we got a shortcut, I can simply use Java space file name
40
00:01:22,000 --> 00:01:24,000
with J, with dot Java.
41
00:01:24,000 --> 00:01:26,000
Say Enter, and we got 12.
42
00:01:26,000 --> 00:01:30,000
So when you say seven plus five, we got 12, cool.
43
00:01:30,000 --> 00:01:33,000
Now what I will do is, so we can add two numbers.
44
00:01:33,000 --> 00:01:34,000
What about supply action?
45
00:01:34,000 --> 00:01:34,000
Let's try that.
46
00:01:34,000 --> 00:01:37,000
So I will say minus symbol and run.
47
00:01:37,000 --> 00:01:38,000
You can say we got two.
48
00:01:38,000 --> 00:01:39,000
So just working.
49
00:01:39,000 --> 00:01:40,000
So we can add two numbers,
50
00:01:40,000 --> 00:01:42,000
we can supply two numbers.
51
00:01:42,000 --> 00:01:43,000
How about multiplication?
52
00:01:43,000 --> 00:01:44,000
We can do that.
53
00:01:44,000 --> 00:01:47,000
So we can say star num1 into num2.
54
00:01:47,000 --> 00:01:48,000
Come back here.
55
00:01:48,000 --> 00:01:50,000
Run, you can see we got 35.
56
00:01:50,000 --> 00:01:51,000
So seven into five is 35.
57
00:01:51,000 --> 00:01:52,000
That work, that is working.
58
00:01:52,000 --> 00:01:54,000
How about division?
59
00:01:54,000 --> 00:01:55,000
Let's try that.
60
00:01:55,000 --> 00:01:56,000
So the moment I said division, we have
61
00:01:56,000 --> 00:01:57,000
to use a slash.
62
00:01:57,000 --> 00:01:59,000
Okay, so we don't have a division
63
00:01:59,000 --> 00:02:00,000
in fact, that's how we do, right?
64
00:02:00,000 --> 00:02:03,000
We underscore or something with a slash.
65
00:02:03,000 --> 00:02:07,000
So yeah, we got slash, let's try and you can see we got one.
66
00:02:07,000 --> 00:02:08,000
That's right.
67
00:02:08,000 --> 00:02:09,000
One is a question here, right?
68
00:02:09,000 --> 00:02:12,000
So when you divide seven by five, you get two things.
69
00:02:12,000 --> 00:02:14,000
One is a question, which is one,
70
00:02:14,000 --> 00:02:16,000
and then you will also get a remainder.
71
00:02:16,000 --> 00:02:18,000
Now in this case, when you use slash,
72
00:02:18,000 --> 00:02:21,000
you will only get a question, not a remainder.
73
00:02:21,000 --> 00:02:22,000
So how will you get a remainder?
74
00:02:22,000 --> 00:02:25,000
In that case you have to use a modulus operator.
75
00:02:25,000 --> 00:02:28,000
So we can use, when you say percentage symbol like this,
76
00:02:28,000 --> 00:02:30,000
it is a modus operator that
77
00:02:30,000 --> 00:02:33,000
what it will give you is only a remainder.
78
00:02:33,000 --> 00:02:36,000
So if I run this code, you can see we got two,
79
00:02:36,000 --> 00:02:37,000
two's a remainder here right.
80
00:02:37,000 --> 00:02:39,000
Now We can use any complex numbers as well,
81
00:02:39,000 --> 00:02:41,000
whatever number you want to perform with,
82
00:02:41,000 --> 00:02:43,000
and I would suggest you to try a certain example so
83
00:02:43,000 --> 00:02:46,000
that you'll get the, get used to this operations.
84
00:02:46,000 --> 00:02:48,000
Now all this operation actually makes sense, right?
85
00:02:48,000 --> 00:02:50,000
These are very simple stuff to understand.
86
00:02:50,000 --> 00:02:52,000
Can we use some other operators as well?
87
00:02:52,000 --> 00:02:53,000
Let's try.
88
00:02:53,000 --> 00:02:55,000
What I will do now is let me just remove this result
89
00:02:55,000 --> 00:02:57,000
for time being, or maybe I can just comment this part.
90
00:02:57,000 --> 00:03:00,000
I also don't need this num2, let me only focus on the
91
00:03:00,000 --> 00:03:02,000
first variable, which is num1.
92
00:03:02,000 --> 00:03:06,000
Now, let's say I want to add this num1 by two.
93
00:03:06,000 --> 00:03:09,000
So basically the value of num1 is seven.
94
00:03:09,000 --> 00:03:11,000
I want to increment the value by two.
95
00:03:11,000 --> 00:03:14,000
So what we can do is we can say num1 is equal to.
96
00:03:14,000 --> 00:03:16,000
So basically we have to use num1,
97
00:03:16,000 --> 00:03:18,000
which is num1 in this case,
98
00:03:18,000 --> 00:03:21,000
and we'll add a value to it, which is two.
99
00:03:21,000 --> 00:03:23,000
And then whatever new value you will generate
100
00:03:23,000 --> 00:03:25,000
after this will be assigned to num1.
101
00:03:25,000 --> 00:03:27,000
Okay, that looks cool, right?
102
00:03:27,000 --> 00:03:28,000
Let's try this.
103
00:03:28,000 --> 00:03:30,000
I will say num1, between num1,
104
00:03:30,000 --> 00:03:31,000
and let's run this code.
105
00:03:31,000 --> 00:03:32,000
You can see we got nine.
106
00:03:32,000 --> 00:03:33,000
So this is working,
107
00:03:33,000 --> 00:03:34,000
so seven became nine.
108
00:03:34,000 --> 00:03:36,000
So just working right.
109
00:03:36,000 --> 00:03:36,000
Now when you know
110
00:03:36,000 --> 00:03:40,000
that you are adding the number by itself, okay,
111
00:03:40,000 --> 00:03:44,000
what you can do is you can just use a shortcut.
112
00:03:44,000 --> 00:03:45,000
Now what that shortcut says is,
113
00:03:45,000 --> 00:03:47,000
let me just comment this section here
114
00:03:47,000 --> 00:03:49,000
and let's write it fresh here.
115
00:03:49,000 --> 00:03:52,000
So we'll say num1, see you want to increment the value
116
00:03:52,000 --> 00:03:53,000
of num1 by two, right?
117
00:03:53,000 --> 00:03:55,000
You want to add itself by two.
118
00:03:55,000 --> 00:03:59,000
So you can say, I want to add myself, but how much value?
119
00:03:59,000 --> 00:04:01,000
So I have to say equal to two.
120
00:04:01,000 --> 00:04:04,000
So what we're saying is we want to increment num1
121
00:04:04,000 --> 00:04:06,000
by two, even this should work.
122
00:04:06,000 --> 00:04:07,000
Let's try, oh, we got an error
123
00:04:07,000 --> 00:04:10,000
because I forgot the semicolon.
124
00:04:10,000 --> 00:04:12,000
And let me just clear this, run.
125
00:04:12,000 --> 00:04:13,000
And you can see we got nine.
126
00:04:13,000 --> 00:04:14,000
So this is working, cool.
127
00:04:14,000 --> 00:04:16,000
Now it's not just variation, we can do that
128
00:04:16,000 --> 00:04:18,000
for any other operation.
129
00:04:18,000 --> 00:04:21,000
Maybe you want to subtract a number by two.
130
00:04:21,000 --> 00:04:23,000
So we can say subtract equal to two.
131
00:04:23,000 --> 00:04:24,000
So it will reduce the value by two.
132
00:04:24,000 --> 00:04:27,000
You can see got we got five, we can multiply
133
00:04:27,000 --> 00:04:28,000
with some other number.
134
00:04:28,000 --> 00:04:31,000
Maybe I want to multiple the same number
135
00:04:31,000 --> 00:04:33,000
with another number and assign it.
136
00:04:33,000 --> 00:04:36,000
So we've got 567 into 856.
137
00:04:36,000 --> 00:04:37,000
We can divide as well.
138
00:04:37,000 --> 00:04:38,000
And so you can use slash
139
00:04:38,000 --> 00:04:39,000
and all the operators, which you have.
140
00:04:39,000 --> 00:04:41,000
Awesome, so this is shorthand.
141
00:04:41,000 --> 00:04:43,000
Now going back to the additional operator,
142
00:04:43,000 --> 00:04:45,000
and then let's say if you want to add it by two,
143
00:04:45,000 --> 00:04:47,000
we can simply mention the value two, right?
144
00:04:47,000 --> 00:04:49,000
We can also add it by one.
145
00:04:49,000 --> 00:04:51,000
So in this case, if you say added by one, the value
146
00:04:51,000 --> 00:04:55,000
of num1 is seven, and then you are adding it by one.
147
00:04:55,000 --> 00:04:57,000
You can see we got eight.
148
00:04:57,000 --> 00:04:59,000
Now in fact, there's a shortcut for this as well.
149
00:04:59,000 --> 00:05:04,000
What you can do is instead of using num plus equal to one,
150
00:05:04,000 --> 00:05:08,000
you can also say num1 plus plus even this is possible,
151
00:05:08,000 --> 00:05:09,000
let's remove the space in between.
152
00:05:09,000 --> 00:05:12,000
So even this is possible, you can say num1 plus plus,
153
00:05:12,000 --> 00:05:14,000
which is incrementing.
154
00:05:14,000 --> 00:05:17,000
So what we are doing here is something called increment.
155
00:05:17,000 --> 00:05:19,000
And if you're on this call, you can say we got eight.
156
00:05:19,000 --> 00:05:22,000
So this operation, let me just make it one.
157
00:05:22,000 --> 00:05:25,000
So all this operations are similar.
158
00:05:25,000 --> 00:05:28,000
Okay, so why I'm saying similar, why not same?
159
00:05:28,000 --> 00:05:31,000
We'll discuss that in some time, but this is similar
160
00:05:31,000 --> 00:05:33,000
and maybe we have done that before as well.
161
00:05:33,000 --> 00:05:35,000
When we talked about characters, you know,
162
00:05:35,000 --> 00:05:37,000
we remember C plus plus, we done that.
163
00:05:37,000 --> 00:05:40,000
So yeah, we are incrementing here as well.
164
00:05:40,000 --> 00:05:43,000
Now, not just incrementing, we can do decrement as well.
165
00:05:43,000 --> 00:05:45,000
So instead of saying numb plus plus,
166
00:05:45,000 --> 00:05:47,000
we can also say num minus, minus.
167
00:05:47,000 --> 00:05:49,000
So what we are doing now is decrement.
168
00:05:49,000 --> 00:05:52,000
So when you say plus, plus, that is increment.
169
00:05:52,000 --> 00:05:53,000
Let me comment this part.
170
00:05:53,000 --> 00:05:56,000
And here I will say num minus minus.
171
00:05:56,000 --> 00:05:57,000
Now why you have
172
00:05:57,000 --> 00:05:59,000
to commend this, but I want to run this.
173
00:05:59,000 --> 00:06:00,000
So we can say now minus, minus,
174
00:06:00,000 --> 00:06:03,000
let's run this code if, see if this works.
175
00:06:03,000 --> 00:06:04,000
And you can see we got six.
176
00:06:04,000 --> 00:06:07,000
So that's how you can perform this addition,
177
00:06:07,000 --> 00:06:09,000
subtraction, multiplication, division,
178
00:06:09,000 --> 00:06:11,000
and increment, decrement.
179
00:06:11,000 --> 00:06:13,000
In fact, we have also talked about modulars, which is
180
00:06:13,000 --> 00:06:15,000
for finding the remainder.
181
00:06:15,000 --> 00:06:17,000
Okay, now that was about increment decrement, right?
182
00:06:17,000 --> 00:06:19,000
We have talked about that.
183
00:06:19,000 --> 00:06:22,000
Now, instead of using plus plus we can actually use
184
00:06:22,000 --> 00:06:24,000
something called, let me just write it in comment.
185
00:06:24,000 --> 00:06:26,000
So instead of saying num1 plus plus,
186
00:06:26,000 --> 00:06:29,000
we can also say plus plus num1.
187
00:06:29,000 --> 00:06:30,000
You know, just to simplify this example, instead
188
00:06:30,000 --> 00:06:33,000
of saying num1 everywhere, let's say num, so
189
00:06:33,000 --> 00:06:35,000
that maybe you will not get, you will get confused by
190
00:06:35,000 --> 00:06:38,000
that one extra symbol there, which is one,
191
00:06:39,000 --> 00:06:41,000
just ignore all this operation, just focus on this part,
192
00:06:41,000 --> 00:06:42,000
which is num and num.
193
00:06:42,000 --> 00:06:45,000
Also, remove this, also remove this.
194
00:06:45,000 --> 00:06:46,000
Let's see if this is working.
195
00:06:46,000 --> 00:06:47,000
Okay, this is working.
196
00:06:47,000 --> 00:06:48,000
So basically we can also say instead
197
00:06:48,000 --> 00:06:52,000
of saying num plus plus, we can also say plus, plus num.
198
00:06:52,000 --> 00:06:54,000
Now what's the difference between this two?
199
00:06:54,000 --> 00:06:54,000
Even this also work.
200
00:06:54,000 --> 00:06:56,000
Let me just try that and show you.
201
00:06:56,000 --> 00:06:58,000
You can say we got eight, we are incrementing the value.
202
00:06:58,000 --> 00:07:00,000
Even this will give you eight.
203
00:07:00,000 --> 00:07:01,000
But what's the difference?
204
00:07:01,000 --> 00:07:04,000
What's the difference between writing this afterwards
205
00:07:04,000 --> 00:07:06,000
and writing before the variable?
206
00:07:06,000 --> 00:07:09,000
So basically we have a different names to it.
207
00:07:09,000 --> 00:07:11,000
So whenever you perform operation
208
00:07:11,000 --> 00:07:13,000
after the variable, maybe it is for additional
209
00:07:13,000 --> 00:07:17,000
or supply, it is for increment or decrement.
210
00:07:17,000 --> 00:07:21,000
So when you do it post, we say it is post increment.
211
00:07:21,000 --> 00:07:22,000
And when you do pre
212
00:07:22,000 --> 00:07:25,000
before the variable, it is called pre increment.
213
00:07:25,000 --> 00:07:27,000
Okay, so when we are doing it afterwards,
214
00:07:27,000 --> 00:07:28,000
we say post increment.
215
00:07:28,000 --> 00:07:31,000
When you say before it is doing pre increment,
216
00:07:31,000 --> 00:07:32,000
now you might be thinking, hey,
217
00:07:32,000 --> 00:07:33,000
ultimately the value is same, right?
218
00:07:33,000 --> 00:07:36,000
So even if you pull, even if you do this
219
00:07:36,000 --> 00:07:38,000
or this, both will increment the value.
220
00:07:38,000 --> 00:07:41,000
Then why we have two different syntax for it.
221
00:07:41,000 --> 00:07:43,000
Why not just simply one?
222
00:07:43,000 --> 00:07:46,000
The answer is it behaves differently when you try
223
00:07:46,000 --> 00:07:48,000
to assign a value, when you try to fetch the value,
224
00:07:48,000 --> 00:07:52,000
let me repeat, these two operations will behave differently
225
00:07:52,000 --> 00:07:54,000
when you try to fetch the value.
226
00:07:54,000 --> 00:07:56,000
Okay, let me tell you what I'm talking about.
227
00:07:56,000 --> 00:07:57,000
Let me show you it here.
228
00:07:57,000 --> 00:07:57,000
Let's come back here
229
00:07:57,000 --> 00:08:00,000
and let's say I have a different variable, which is int,
230
00:08:00,000 --> 00:08:02,000
and then I'm storing that in result
231
00:08:02,000 --> 00:08:04,000
and what I'm storing is num
232
00:08:04,000 --> 00:08:06,000
or maybe I will say plus, plus num.
233
00:08:06,000 --> 00:08:09,000
Okay, now think about this and maybe you can pause the video
234
00:08:09,000 --> 00:08:11,000
or whatever you wanna do.
235
00:08:11,000 --> 00:08:14,000
Just think about what will be the value of result.
236
00:08:14,000 --> 00:08:16,000
I will say result here to print,
237
00:08:16,000 --> 00:08:18,000
and maybe you have done your thinking, let's run this
238
00:08:18,000 --> 00:08:20,000
and you can see we got eight.
239
00:08:20,000 --> 00:08:22,000
So what is happening here is the initial value
240
00:08:22,000 --> 00:08:23,000
of num is seven.
241
00:08:23,000 --> 00:08:26,000
And then you are saying plus, plus plus num.
242
00:08:26,000 --> 00:08:28,000
That means you are incrementing it, that
243
00:08:28,000 --> 00:08:31,000
incremented value will be assigned to result.
244
00:08:32,000 --> 00:08:34,000
And then you got result, which is eight.
245
00:08:34,000 --> 00:08:35,000
So initially I've also mentioned
246
00:08:35,000 --> 00:08:37,000
that this two will be incrementing.
247
00:08:37,000 --> 00:08:39,000
So we can also say num plus plus, even they should
248
00:08:39,000 --> 00:08:40,000
be doing the same thing, right?
249
00:08:40,000 --> 00:08:43,000
Let's try, oh, there's a twist here.
250
00:08:43,000 --> 00:08:46,000
So plus plus num and num plus plus are not same.
251
00:08:46,000 --> 00:08:48,000
I mean it works same with their individual statement,
252
00:08:48,000 --> 00:08:51,000
but when you try to fetch the value from them when they're
253
00:08:51,000 --> 00:08:53,000
performing the operation, they behave differently.
254
00:08:53,000 --> 00:08:56,000
So let's understand why it is called pre increment
255
00:08:56,000 --> 00:08:58,000
and what is called post increment.
256
00:08:58,000 --> 00:09:00,000
So whenever we use assignment operator with this operation,
257
00:09:00,000 --> 00:09:03,000
what it will do is it will check, hey,
258
00:09:03,000 --> 00:09:04,000
we have an operation which is num plus plus,
259
00:09:04,000 --> 00:09:06,000
but that's a post increment.
260
00:09:06,000 --> 00:09:09,000
So first it will fetch the value of num, let me repeat.
261
00:09:09,000 --> 00:09:12,000
It will first fetch the value
262
00:09:12,000 --> 00:09:15,000
and then increment.
263
00:09:15,000 --> 00:09:16,000
In fact, it looks like one statement,
264
00:09:16,000 --> 00:09:18,000
but we have two statements here, right?
265
00:09:18,000 --> 00:09:20,000
In fact, we have this statement here,
266
00:09:20,000 --> 00:09:22,000
num one equal to num plus one.
267
00:09:22,000 --> 00:09:26,000
So what it'll do is it'll first fetch the value of num,
268
00:09:26,000 --> 00:09:27,000
which is seven in this case,
269
00:09:27,000 --> 00:09:30,000
and then it will increment the value of num
270
00:09:30,000 --> 00:09:32,000
and will make it eight, okay?
271
00:09:32,000 --> 00:09:34,000
But then what is assigned to result is seven itself,
272
00:09:34,000 --> 00:09:37,000
and then you are printing that seven here, okay?
273
00:09:37,000 --> 00:09:38,000
But what will happen when you
274
00:09:38,000 --> 00:09:40,000
say, let me just write it here.
275
00:09:40,000 --> 00:09:44,000
So we'll say end result is equal to plus, plus num.
276
00:09:44,000 --> 00:09:47,000
In this case, what will happen is it will first increment
277
00:09:47,000 --> 00:09:49,000
and then fetch the value, okay?
278
00:09:49,000 --> 00:09:51,000
So it will first increment itself
279
00:09:51,000 --> 00:09:52,000
and then it will fetch the value.
280
00:09:52,000 --> 00:09:54,000
And that is what is going in result.
281
00:09:54,000 --> 00:09:55,000
I hope this makes sense, right?
282
00:09:55,000 --> 00:09:58,000
So this is how your code works when you say plus, plus num
283
00:09:58,000 --> 00:10:01,000
and num plus plus, in fact, we'll do some more operations
284
00:10:01,000 --> 00:10:03,000
with this once we get started
285
00:10:03,000 --> 00:10:06,000
and it will make much more sense later.
286
00:10:06,000 --> 00:10:08,000
So in the operators, we have talked about other
287
00:10:08,000 --> 00:10:09,000
thematic operator until this point.
288
00:10:09,000 --> 00:10:10,000
So whatever option you have done, it is
289
00:10:10,000 --> 00:10:12,000
for the Arithmetic purpose, right?
290
00:10:12,000 --> 00:10:14,000
Addition, subtraction, multiplication, and division.
291
00:10:14,000 --> 00:10:16,000
But what if you want to compare to values?
292
00:10:16,000 --> 00:10:18,000
What if you want to have compound conditions?
293
00:10:18,000 --> 00:10:20,000
Okay, what are those things, we'll talk about
294
00:10:20,000 --> 00:10:22,000
that in the upcoming videos.
|