 So, as I said this is basically going to be recap of lecture numbers 408, 409, 410 which are already there. So, I am going to sort of go over some of the important slides very quickly and then we will start with the questions ok. So, this was recap 1 which was about lecture number 408. So, in that lecture we basically looked at assignment statements right and you have already seen assignment statements in some of the earlier programs that we have played in videos in the class. So, statements like A is assigned B plus C they mean two different things I mean when you write A the equal to symbol and then B plus C they mean two completely different things in C plus plus as opposed to maths right and I believe all of you I mean even those who have not seen the videos will be able to understand this right. And then there are arithmetic expressions and specifically in lecture 408 we looked at the addition, subtraction, multiplication, division and the remainder operator that percent sign constitutes integer remainder and we looked at operator precedence and associativity and we looked at the use of parenthesis right. So, when you have an arithmetic expression and this was discussed in the last class where in one of the practice quizzes there was a floating point number being added to an integer number and several of you ask the question is that allowed and what happens when we do such addition. So, when you write out an arithmetic expression in which there is a mix of types the general rule of thumb is that expression itself has a type which is at least as expressive as its operands. So, if you add float and int you will get a float, but no more you are not going to get double right because double is even more expressive than what you require. So, this is once again in the video lectures which you some of you have seen. So, if I take float a and int b then float is more expressive than int. So, all such things like a plus b, a minus b, a star b, a divided by b will have the type float right at least as expressive as the operands and no more. However, 2 times b will be int because b is int and 2 is also int 2.0 times b will be float because 2.0 is floating point constant we have already seen this and b is an int ok. So, 2.0 when we write it there are two ways of writing floating point constants we clearly said this that you put a decimal point and the number becomes a floating point constant or you write it in the scientific notation where it is e plus 10 e minus 10 you remember that. So, this is just that 2.0 the number 2 can be represented as an unsigned integer can be represented as a signed integer can be represented as a floating point. So, we have to tell the computer how it should represent it the moment I write 2.0 it knows that I am I mean otherwise why would I put that point 0 in it. So, double a float b int c double more expressive than float float more expressive than int. So, an expression like this has the type double then this lecture also talked about operator precedences. So, if I write you know this I am just recapping this is not meant to be a lecture where I am trying to explain things to you this is already there and you are supposed to have seen this. So, a plus b star c plus d. So, the question is which of these does it represent which operation should I perform first and this is defined by the operator precedence the precedence among the different operators which operator should be applied first which should be applied next and so on and star has higher precedence than plus in c plus plus. So, first b star c and then you add the other 2 and similarly if you write something like this which of these 2 does it represent. So, here plus and minus have the same precedence however they are going to be evaluated from left to right. So, this is called left associativity and so in this particular case a plus b will be evaluated first then a plus b minus c and then d will be added to it. Multiplication and division and remainder have higher precedence than addition and subtraction but they are at the same level of precedence ok. So, this expression is basically going to be evaluated left to right associative all of them are at the equal precedence fine and this is perhaps different from usual algebra and so the best practice is to use parenthesis unambiguously. So, wherever you want wherever you are not clear that which is going to be evaluated first which is going to be evaluated second write them unambiguously. So, that was lecture 408 and these are perhaps 2 of the central slides of 408 and I have quickly recap that ok. So, the second lecture that you are supposed to see and come was about logical expressions in assignment statements and in other statements also and these were the different things that were covered in that lecture relational operators basically given integers or floating point numbers how do I get a Boolean value out of it I can compare 2 such numbers using one of these operators. So, this is the usual less than less than or equal to greater than greater than equal to this is equal to. So, when I write a equals equals b I am asking is a actually equal to b right. This is the difference between the assignment operator which is 1 equal sign and the equality comparison and this is not equal to and here also we had precedences and associativities and parenthesis and then we also discussed in that lecture the values of logical expressions. So, this we have already seen when we had discussed Boolean data type. So, it is pretty much same here that logical expressions you can think of them as having values true false or if you want to view them as integers it is 0 non 0, but when you print them the C plus plus standard specifies certain things and when you print true as an integer it has to be printed as 1 ok. So, once again I mean since most of you have not seen I just quickly picked up a couple of important slides from this deck of slides and let me play them back. So, logical operators once you have formed logical expressions like this from integers or floating point numbers whatever then you can combine them to have the binary logical and the logical and true and true is true, true and false is false right and that is denoted in C plus plus by 2 ampersons. So, for example, this is saying a is greater than equal to b and a is greater than equal to c there are 2 ampersons signs. Use 2 vertical bars to denote logical or. So, this is the usual Boolean and or that you know of, but the point to remember is that there are 2 ampersons and 2 vertical bars and use a single exclamation symbol to denote logical negation ok. So, for example, this is saying not the case that a is greater than equal to b and a is greater than equal to c and then you can build complex logical expressions using parenthesis and a logical operator a logical expression always evaluates to something of type bool. Presidences among logical operators. So, these have higher precedence than Boolean and or, but these have lower precedence than the complementation. So, that is a very interesting question. So, correct me if I have interpreted your question wrongly I believe what you are saying is that when I write something like a greater than equal to b and a greater than equal to c then we know what it means right, but you are saying that if I did not put these parenthesis. So, if I just wrote it as a greater than equal to b and a greater than equal to c. So, you have a set of operators right here there is a greater than equal to there is an ampersand there is another greater than equal to and in order to evaluate any expression like this is just a logical expression just like we did arithmetic expressions earlier. We need to know the precedence between the operators we need to know which operator should be applied first which should be applied next. So, as I was going to show in the slide after that. So, these enjoy higher precedence than these the Boolean the logical and and logical or are lower in precedence than the comparison operators. So, even if you wrote it like this in C plus plus this operator will be applied first to its arguments this operator will be applied to its arguments and then it will do this right. However, suppose I had something like this not of a greater than equal to b when I write like this it is very clear I have to first compare a with b whether a is greater than equal to b that evaluates to true or false you negate it right. However, if I did not put the parenthesis and just wrote like this right. So, as I was just showing in the next slide this enjoys higher precedence than this. So, in this case this will be evaluated first. Now, if a is an integer what does it mean to say not of a here is where you know we go back to what we have learnt earlier that any nonzero value will be treated as true 0 will be treated as false. So, if the value of a is 0 then that not of a will evaluate to true if the value of a is nonzero not of a will evaluate to false, but then after having evaluated I need to do this comparison right. Now, in this comparison I should be comparing to integers right I am comparing greater than equal to or less than or equal to whatever right. So, in this case if a is 0 let us say the not of a will be some nonzero value depending on how the computer stores true as a nonzero value it I mean it is allowed to store it as any nonzero value. So, it can store it as 1 or it can store it as 137 depending on what that value is that integer will be compared with b and then you will get a Boolean value of what not a greater than equal to b is right. So, if you write things like this as you can see that you are making things dependent on the computer's internal representation right. So, therefore, whenever there is a doubt just put parenthesis you know stay away from such you know evaluations being dependent on some complicated operator precedences is this clear. So, in this case it would not make a difference because these are in any case higher precedence than this, but in this case it would make a difference because this is higher precedence than that. And in this case this integer will first be treated as a Boolean then the resulting Boolean will again be treated as an integer and then you will get some final result and so it all depends on how Booleans are being stored internally as integers in the computer ok. These have the same precedence, but their precedence is lower than the negation operator which we just saw and they are all left associative. These have the same precedence and they are lower than the less than less than or equal to and so if I write something like this it will be interpreted as something like this because this has lower precedence than this ok. And then among these logical operators this has the highest precedence its precedence is lower than equal to and equal to precedence is lower than less than. So, these are going to be you know much lower. So, the best practice is to use parenthesis unambiguously ok. So, when you are writing a program you do not want the result of your program to depend on how the computer represents Booleans internally you want a deterministic result ok. So, once again this is a slide from that slide back from the video lecture and these have been explained there ok. Now, the third lecture which you are supposed to have seen which is 4.10 that was about sequential execution of statements and it also showed that in a program declarations are not executed at runtime these are things that the compiler uses to store. So, the third lecture was about sequential execution declarations separating two statements with semicolon and then you can execute statements left to right and top to bottom. So, once again since several of you did not see I have picked up some slides a couple of slides from the slide deck and the simplest programs are really linear sequence of instructions the computer executes the instructions in linear order. So, here is a simple program which you know based on what we have discussed right now and what you have learnt in the previous classes you should be able to figure out what this is doing right. And we are just going and on the right hand side that black part is kind of like what your computer screen might show as this program executes. So, there is a little animation here which tries to show how the program gets executed which statement gets executed and what its effect is. So, all of you will be familiar with this we had the Dumbo animation this is basically a similar thing happening on your C++ program. So, in ABC is a that is visible that is a declaration the computer does not execute that statement there is nothing to execute is basically telling the compiler how many bytes to store for ABC. Similarly, bool is a largest is a declaration there is nothing to execute. So, that running icon is basically showing what the computer executes that is the part really executes right. So, the first statement in this program that is actually executed by the computer is that give three numbers followed by end of line. So, on the so when that is executed this is what you can expect. So, this could be your favorite prompt give three numbers and end of line. And then it is going to read three numbers right that is the next instruction. So, the next instruction is it wants to read three numbers. So, it is waiting for you to enter three numbers. So, this is an instruction that the computer is executing, but you have to give three numbers for the execution of this instruction to complete. So, if you give one number and then press enter the execution of that instruction is not complete yet right. So, it will wait for you and then if you give another number space a number now it has got three numbers and now when you hit enter the execution of that CN is complete and it will go to the sequentially next instruction that it can see right. So, it is just coming top down in the program executing one instruction after the other whatever is executable the declarations are not executable it does not execute those. So, now when this instruction is executed right what is this doing it is basically figuring out if a is the largest of the three right. There is nothing that is going to be printed. So, the computer will execute this instruction, but there is no input output. So, this is happening inside the computer. And then after that it prints this it executes the next instruction. So, is a largest and then it prints the value of a. So, in this particular case I believe 23 is larger than minus 320. So, it will say that yes a is the largest and when it prints out is a largest that being a boon when I try to print it out it will print one and that is the execution of this next instruction. After that what happens? So, basically when this last instruction is executed this is what you are going to get, but the control is still not back at the prompt I mean the operating system still has not got the control back. So, it is only when this return is executed does the control come back to the operating system and then you can enter your next command. So, if you do not give that return then control does not go back to the operating system. What if you use void main? So, in the previous lecture I showed that there is a data type void in which it is basically not used for storing any values. So, even if you had void main you would have to say return. Now, what is going to happen is in your compiler I believe in the code blocks compiler if the main function does not have a return it implicitly puts a return in there, but when you start functions and they do not have a return it will complain. It will say how do I go back from here? You know I can come into this, but how do I go back from here? That since main is a designated top level function and after the last instruction is executed we can put a return there. So, but some compilers will still complain that your main function does not have return. So, even if you have void you are supposed to put a return saying that return and you need not pass a value you can just say return semicolon. And then after that we had a simple C++ program to find if b divides a. So, hash include ios stream using namespace std there were lots of questions at the end of last class about what using namespace std does I hope it is clear now we dwell on that significantly. And then comments very important when you write programs you know you need to tell what a program is doing through the comments. So, that is the main function. So, there are three variables called a, b and r give a and b reads a and b computes the remainder of a divided by b sets a flag which is declared to be of type boolean actually that is missing over here there should have been a variable of type boolean over here it is there in the video recording this is a slightly older version of the slides. So, this divides flag is a boolean variable which is set equal to the result of comparing r with 0 and the comparison operator is the equality operator ok. And then does b divide a you print out that flag ok. So, if b does indeed divide a then this remainder is 0 divides flag is true and you get a 1 here if b does not divide a the remainder is non-zero divides flag is false and you get a 0 there ok. And this is just sequential execution of statements the declarations are not to be executed and then you just execute the statements one after the other and then you return and this semicolon is basically used to separate out one executable statement from the next even if I wrote you know after c and a b even if I wrote r is equal to a percent b r is assigned a percent b over here to the right of it that will also be fine. So, statements are executed one line at a time and in each line from left to right and it uses the semicolon to figure out which statement comes first and then which statement right. So, left to right top to bottom is the execution order and the sequence is important for example, here if these two were swapped for example, suppose I first said that divides flag is assigned r equal to equal to 0 and then I computed r to be a percent b then of course, it is not going to do the right thing right. It is going to use the value of r before it computes the remainder and it will use. So, remember the Dumbo model of computing every drawer starts off with some value if you or your program did not write a value there then it is some garbage value over there. So, if you swap the swap these two statements then the value of r that is going to be used could be the garbage value once again something for which you can lose your job if you do this in the industry. You should never use a variable before it is assigned or initialized otherwise the result can be non-deterministic right it depends on what garbage was stored there ok. So, those were the recap slides I guess I have spent as much time recapping as the actual video lectures, but in the process we also answered some questions ok. So, now what we are going to do is we are going to show you some questions and how we should really be conducting our class from next time onwards. You should have seen all of those videos we will start off with questions you know I might give just the basic recap bullets at most not the actual slides. We will start off with questions you have to write your questions swap it with your neighbors discuss it with your TAs and you know try to understand each other's reasoning and so here is the first question. So, a is of type char b is of type int c and d are of type double and you have to identify the data type of the expression a star b plus c minus d ok. Now, here is the second question identify the correct order of preference for the expression where we have only used plus minus and star.