 So, first was about the assignment statement. In that lecture, Supratik explained that the assignment statement like A equal to B plus C is different in a programming language than in maths. It is not an equation. We had seen that even when we discussed an artificial assignment operation done by our character Dumbo. So, we know what this means. This particular assignment operation hinges around the equal to symbol. This is not the mathematical equal to, once again I repeat, this is an assignment operator. It has two sides and the statement requires C plus plus to undertake two tasks. One sub task is to evaluate the expression on the right hand side, which is B plus C in this case. It will take values of location B and C, calculate that expression, get one single result value. It is only then that C plus plus looks at the left hand side of the equal to symbol. Till then it does not care what is there on the left hand side. On the left hand side, it must find a single name, a single variable name to which a value can be assigned. It simply takes the value that it has calculated by evaluating B plus C and assigns that value to A. On the right hand side, the expression that is written could be containing variety of elements and variety of operators. For example, arithmetic expressions will have these symbols. Now these symbols, when you have multiple symbols, obviously they will have to be some precedence and some associativity too. And wherever you want the precedence to be indicated different from what is implied by the operator, then you can use parenthesis as in any algebraic expression that you do. So, anybody who remembers the precedence between these operators, first of all, are you all familiar with these operators? Plus, minus, multiplication, division and what is this? Modular Amanda. This operator works only with two integer operands. So, which of them are higher priority and which of them are lower priority? Last three are higher priority, first two are lower priority. Now you might mix in the expression elements of different types. So, what are the different arithmetic types that you have? Numerical types, integer with its own variations, floating point, float, double, bool. So, these are the various types. And there is something called more expressive type to which the less expressive type is converted. For example, floating point can represent larger magnitude of number. So, it is considered more expressive than integer. And if you mix two operands, one of integer type, one of floating point type, then the integer type is converted before the operation to the floating point. If both operands are of the same type, the result of any sub expression is same. If the operands are of a different type, then you follow this rule. But it does this and nothing more. So, for example, if I have float a and int b, the float is more expressive than int. And therefore, a plus b, a minus b, a star b, a slash b are all float. Why? Because one of them is float, the other is integer. So, int will be converted to float. On the other hand, 2 star b will be evaluated as integer because 2 is an integer constant. But if I write this as 2.0, then 2.0 star b will be evaluated as a floating point value. Is that clear? So, suppose I have these declarations, double a, float b and int c. Now, double is considered more expressive than float. You can reason it out naturally because double has a larger precision as well as large amount. And float is more expressive than int. So, that is how the conversion will happen. So, a plus inside parenthesis b star c will have type double. c is int, but b and c are, b is float. So, b star c will be float. a is double. So, a plus anything will be double. So, that anything will be converted into double internally while doing this. So, what is this? Just remember the previous line a is double, b is float, c is int. So, this is clearly a completely separate statement which has nothing to do with the declarations that you saw earlier. All right. Assume that a, b, c, d are of the same type or do not worry about the type conversion. But the question is, in what order this expression will be evaluated? Will it be evaluated like this? Yeah, because star has a higher precedence than plus. So, star has a higher precedence than plus. So, this will be done first. What is a plus b minus c plus d? All are at the same precedence. So, the calculations will proceed from left to right because the associative rule says left to right. So, which way will this be done? So, it will first calculate a plus b, then calculate the subtraction of c, and then the final result you will add plus d. So, left association is the standard association. There are some exceptions that we shall see later. Similarly, star slash and modulo operator have the same precedence and they are left associated. So, please note that this is different from usual algebra where you do not have a modulo remainder symbol per se, but you normally would not associate with it a high enough priority, whereas in c plus plus you would. And the best practice is to use parenthesis whenever you have any confusion. Then we discuss the logical operators and the logical expressions and they these operate on logical values which either are defined as bool variable values or constants true and false or they are generated from comparison of numerical values, comparison of logical whatever and whenever such values are to be operated upon, you use logical expression. So, first and foremost you have these relational operator. So, please note when you want to compare two values being equal or not, you say equal equal. Why? Because a single equal is considered the assignment operator is also an operator. Just one equal to symbol is an operator a equal to 5. So, equal to is an operator which assigns the value 5 to a. Curiously when you conduct an assignment operation, the assignment operation itself has a value which is the value which is finally assigned to the left hand side variable. So, a equal to 5 as a whole expression is considered an expression with equal to operator and that expression results in the value 5 because 5 was the value which was assigned to a. However, that is treated as an assignment operation and therefore, if you want to check equality you will do this. This is not equal to an exclamation mark followed by equal. Again there are operator precedences and associatives and use of parenthesis is recommended. The value of any logical expression is either true or false. Zero is false. A zero is false and non-zero. Any non-zero value will be true. Printing values of logical expression we saw independent of whatever is the non-zero value stored while if you print and a logical value is true, it will always print one that is the stipulation of C plus. There are logical operators which you by which you can combine multiple logical values or logical expressions. So, these are two ampersands to represent logical and there is binary logical and so a greater than equal to b and a greater than equal. So, note if you want to say that a is greater than b as well as a is greater than c, then only this entire expression will be true. If only one of the sub expressions is true, the other is false, the total value will be false. So, you know that simple logic true and true is true, true and false is false, false and false is false. Exactly the same thing about r. So, r is represented by two vertical bars and you can have this expression as this or this. So, again the truth table for r is well known. One single exclamation mark is a negation. So, not of true is false, not of false is true and this logical not can be put on the entire expression. So, can you tell me when this entire thing will be true and when this entire thing will be false? So, this is the precedence. Comparison operators have same precedence lower than exclamation mark, then they are left associative. Equal equal not equal have same precedence lower than less than left associative. A greater than b not equal to b less than c is interpreted as a greater than b not equal to b less than. So, please note that this not equal to symbol has a lower precedence than comparison operator. So, comparisons will be done first this and this comparison and then the two logical values will be combined by not equal. The logical operators not and and are all of them have precedences lower than the comparison operators but within them not has the highest precedence and has a precedence lower than equals is left associative and or has a precedence lower than and it is left associative. So, for example, not flag 1 or flag 2 and not flag 3 is a complex logical expression. This should be interpreted as not of flag 1 or flag 2 and not of flag 3. So, you can just apply those rules of precedence and interpret. However, as it was stated earlier even in the slightest now you just use parenthesis to properly reflect what you have in mind. Next, we discussed in the video the sequential execution of a program. We had again seen that in our plain Dumbo animation as well. The point that is to be remembered is any declaration is not executed at runtime. So, just like when I say in something float something these are all declarations. We had also seen some funny looking statements like include something using namespaces. These are all declarations. They are read by the compiler. Some action is taken during compilation but that's it. When the program is to be executed only executable instructions of your program are executed and they are executed linear. We use semicolon to separate one executable statement from the next. Consequently, it is possible to write several statements in a single line because they are all uniquely separated by semicolons. The execution is always left to right and top to bottom as we would read a standard textbook. The simplest programs will represent a linear sequence of instructions and these instructions are executed in the linear order. So, when you use your code blocks, for example, you would have a window on your right hand side. This represents your computer screen and let's say this is the program. So, let us now see how this program is compiled and executed by the C++. You can see a small block coming there on the left. That is like a thought process. The compiler is not executing anything but it will notice that you are declaring three variables ABC, all are integers. So, it will actually allocate memory. There are no more drawers and a chest and so on but now you have so many bytes. So, an int is how many bytes? Four bytes. So, it will allocate three locations each of four bytes. The next bool is a largest. Now, there's some kind of a flag variable. We want that to be either true or false. Obviously, if you look at the name, e is a largest. We are asking a question to the program. If it is largest, we expect it to be true. If it is not largest, we expect it to be false. That's the intention. As far as compiler is concerned, it doesn't give a damn as to what is the meaning of the name that you give. Name is your choice. Internally, it might choose any numbered location, 1, 2, 1, 0, 0, 2, 1, whatever, whatever, some location. What will be the length of that location for bool? Technically, a bool has to be either true or false. So, one bit is adequate. The bit can be 0 or 1. It so happens that in a real machine, a bit cannot be uniquely addressed. So, it all depends upon the addressing mechanism the computer uses. C plus plus does not stipulate how many bytes should be used for storing a bool. Typically, it could be a one byte value. It could be a four byte value. It could be any value. But this is also an internal process of compilation. This is a statement which will be executed. So, you see a small fellow running. This shows the computer is running to do something. The action will happen here. So, the see out statement is an output statement. You have the stream operator here. Less, less means show this out. End L means end of life. So, this is where you will see give three numbers. My prompt colon is actually an indication that most of the operating system environments where you will execute your program will give you a prompt where you can give commands. In code blocks you will not see this prompt. But you will only see a cursor coming there. The cursor, wherever the cursor is it will show either the next output is going to come there or next input has to be typed by. The next statement is an input statement. So, when this is executed you have to start giving values. Please note that this statement asks for three input values. It is possible to do that. An individual element can be written separately by greater, greater, greater, greater, greater, greater. Notice that if I give 23 and press enter the input operation has not ended because the input is waiting for three values. And as we showed the dumbo will wait eternally till you complete that action. So, does C++. So, after entering 23 the job is not done. The machine is still waiting for input. Let's say you give two values here minus 300 and then 20 then enter. But at this point the machine figures out that it has the three values. It will take those three values and proceed further. Please note that the values need to be separated by either a blank or a tab or by a new line. So, you can give these three values in three different lines by pressing enter, enter after every value or write all three one after another but with a space. What will happen if you don't give a space between the values? Yeah, if I don't have this space for example the value will be treated as 30020 minus 30020. It can't distinguish without a blank in between the values. Next it will execute this statement. Nothing appears on the screen of course but internally what would happen? So, the expression on the right will be evaluated. This is a logical expression. This will result in a truth value, a bool value true or false and that will get assigned to is a largest. Notice how this flag is beautifully used in getting my result directly. Is a largest? C out is a largest? Answer is one. Why the answer is one? Because of the three values which are given by me 23 minus 300 and 20. So, this value 23 goes to a minus 300 goes to b 20 goes to c and you can see that among these three values a is indeed the largest. So, when it does these comparisons it will actually evaluate to true is largest will be true and that is what will be printed. Please note that before this cursor was hanging somewhere here. But when you when the Dumbo executes this instructions return zero there is some discussion on return zero here. What is being returned? Why it is being returned? Why zero is being returned? To whom it is being returned? So, please remember the discussion that the entire program is considered as a function. This is the main program and this function is called by the operating system or your code blocks environment when you execute your program. Later on we will see that internally you can write other functions which could be invoked. Now whenever you go to that function that does some calculations it has to return back a value and that is where the word return is used. Return is a statement an instruction in C plus plus which returns a value which you have returned. The normal convention when the main program returns to the operating system is to return a zero to indicate a healthy return that means the job is done. If something goes wrong later on we will see if this if that if that then you want to say no sorry I can't carry on. You have to say you will say return minus one return minus two and there are mechanisms by which you can make the operating system analyze what value was returned and take some action outside this program. This is a C plus plus program here. Include iostream using namespace std. We had had some discussion on this but it doesn't matter if you do not completely follow this because this is just to be taken as minimal required declarations for running a C plus plus. This is a command and no program should ever be written without appropriate commands no program period it is that important. What does compiler do with the commands? Ignore them. And why the hell do we write them? Because other human beings including ourselves are going to read it. Later when you write a 500 line or a thousand line C code spread over multiple functions I will tell you that if the program does not have commands you yourself within a month will not be able to understand what that program does. I can guarantee that after 40 years I expel you. Then what? So forget others for your own sake you should write commands. In fact later on when we discuss the software engineering practices we will see how when you start writing a program not a single line of instruction is written unless you have written the full contour of the program in terms of commands. You first write commands what you are going to write here what you are going to write here what you are going to do next what you are going to do next. You sort of describe your algorithm by commands first and then insert statements in between so that they are appropriately seen. So this is again a standard int main thing there are three variables declared a b and r so this is a variable declaration this statement you already seen it outputs a string and n l is another string this is a standard string which contains what the new line character actually it is a single character so you can also represented by single code backslash n single code escape character followed by n is the symbol. You take an input of a and b then you calculate r which is reminder when a is divided by b so reminder of a divided by b of course you would not like such stupid commands in your programs later here they are written because you are still becoming familiar with what the operators do later on when you know them and you expect all others to know them you will write your commands which are more meaningful describing what a segment of a program does rather than an individual. Notice here again we're in clean use of a flag divides flag equal to r equal equal 0 is the remainder 0 so c plus plus will flag an error because you are not declared it what is missing here so what should I say bool divides flag just I have said in something after this somewhere here in it any place here but before this statement actually is written the divides flag should be declared it is however a good practice to declare all variables that you need bunch them together at the beginning of the program and declare them that's the best practice both for you and and for c plus we are outputting a string does we divide a and then I am outputting the flag if the flag is 0 what do we mean it doesn't divide flag is one it means divide why because r equal equal 0 r will be 0 only the remainder is 0 which means b divides a and therefore the divides flag will be 0 if r is anything else okay r equal equal 0 will be untrue and therefore false will be assigned false will be printed if I were to find out and print the actual value which is larger amongst these two what will I have to do that was a is 25 b is 20 and the question was print the larger value I have read a and b we don't know how to do that yet please understand that because we know that instructions will be executed serial if I have a see out instruction which outputs a then a will be output anytime whatever with the value of a and b if I see out instruction b it will output b whatever with the values of a and b and if I put both it will output both values always so till now we do not know how exactly to do that activity namely find out the maximum of the two values and print that value however by using sequential execution we can actually show whether a value is sorry a divides me or not I I am sorry I'm digressing but if I were to compare these two which is larger we have seen that larger flag kind of thing I can print that larger flag to say whether a is the largest or not but I can't print the largest value so far alright so with this we will now start our questions so this is the first quiz read that quiz and write down your answers the simple quiz it says identify all incorrect statements from the following which are written so a b cd there are four statements written many of them or all of them could be incorrect none of them could be incorrect you have to read each one understand what it means and say whether it is right first statement says all variables must be declared before being used second statement says executable statements are executed in sequence from bottom to top third statement says current value of a variable may refer to any previous value stored in the variable the last statement says current value of a variable refers only to the latest value stored in it so out of these statements which are right and which are wrong very quickly shouldn't take more than 30 seconds as you read them you can figure out is it right or wrong everybody has written good so quickly swap your things this is a simple quiz we don't want to waste too much time on this we are going to more important pieces so let's go to the next quiz which of the following can be used to terminate a sentence in c++ a colon b semicolon c comma d c++ accepts any smiley as a valid terminate all of us would like d but doesn't work that way unfortunate c plus plus is a very stern person like our dumbo so we don't waste time in discussions all right identify the data type of the expression a star b plus c minus d in bracket if a is of type care b is of type in and c and d are of type double all right everybody has written so how many steps you have written there is one operation second operation and third operation so there should be at least three steps in the first step some sub operation takes place you will get a value type second step another sub operation will get a value type third step you'll get the final way everybody has written these three steps all right I think that is sufficient because it's a simple question they are more interesting problems coming up later the first thing to be evaluated will be there is a parenthesis here parenthesis overrides any prior so c minus d will be evaluated c and d are both type double what will be the type of the result double now I have a star b plus some result so a star b plus some result that result is double b is in a square so what will be the sub expression next evaluated please note that the order of evaluation of sub expression is not dependent on that type of individual operands it is dependent on the operator precedence star as a higher precedence then plus therefore a star b will be evaluated first a is care b is in what will be the type of the result in please remember care is internally represented as an integer number and is converted to the more expressive type which is in so a star b will result in an end the third operation is is the result of a star b which is the nint plus the result of c minus d which is double what will be the result double this is the next quiz identify the correct order of preference for the expression a star b slash c plus d minus c star f no type is given is that relevant do we need to know what is the type of a b c etc no that's the important point that type of a value comes into question only when the actual operation is to be carried out and that too in order to understand what type will get converted to what type of value but as far as expression evaluation is concerned it is the precedence and the associativity which decides so here I have a question and the answer to this question is written by writing appropriate number of parenthesis so these parenthesis indicate different order as you can see this is an individual exercise ok here is one answer do you agree with this let's independently figure that out first which of the operators will be executed basically star slash star are the highest priority operators they were left associativity so first this operation will be done then possibly this operation will be done then this operation next you have plus and minus which are the same priority so first the plus operation will be done and then the minus operation I think that is very straightforward just remember one thing psychologically when you write these parenthesis you can see here this parenthesis is larger than this one if you have multiple parenthesis by the time you complete you will have some very large parenthesis now when you type them on the machine the machine unfortunately is incapable of typing parenthesis of different sizes they all will be exactly identical exactly identical just remember this all right so which is the right answer D the another quiz find the value of the following expression given that A and C are true and B is false select all options that apply so please look at this slide but now I am sure half of you would not have written down that expression on your notebook all right so here is an expression now I will flash the logical operator precedence so now you can solve that problem solve it and find the logical value of the expression I'll again draw your attention to this A and C are true B is false this part of the problem all right so this is the precedence apply this precedence logically do those expressions first this time you can actually keep on getting T or F or 0 or 1 whatever you want to say and then you can quickly surmise what would be the final value all right everybody is done now swap your answer works and check your neighbors answer if it does not tally with yours now you can discuss and convince your neighbors all right so select all options that apply does A apply anybody thinks it is not true please raise your hand everybody thinks it is true does B apply cannot if A applies B cannot apply at least that much is clear what about C why does it not apply false does D apply why does it apply how does it become true so what will be evaluated first and now A is true and C is so A and C is true true or B B is false so true or B is true therefore this all right so this question says identify all incorrect logical expressions from the following you don't have to struggle with the values of true and false but given that A B C and D are all Boolean variables which of these expressions will be considered correct expression by the compiler and which of these expressions the compiler will say sorry this is not a correct expression identify all incorrect logical expression so write down in your notebook capital A capital B capital C capital D out of these which ones will be considered as incorrect and write down the answer in your answer a brief explanation of why do you think the compiler will think it is incorrect there has to be a text line so you have capital A capital B capital C capital D has four choices and the way you have to write answer is not by ticking as you do in a competitive exam but you have to write say B is incorrect according to you say you you say B and then write down an English sentence why do you think it is incorrect you have to write A B C D the choices according to you of statements which are incorrect and for every choice that you make you have to write one English sentence as to why it is incorrect that may take more than 30 seconds to do that write down why something you feel is incorrect done alright now swap your notebooks and comment not only whether the choice mentioned is an incorrect statement but also the reason for that please exchange now you have to now you have to see your neighbors notebook and compare things and comment on it is there an agreement any any pair which disagrees either on the choice of incorrect statements in the reason so let me first ask a question to those who agree A and C are incorrect alright what was the reason given by both of you why is A incorrect because of the less than sign and in the C part equal to sign less than sign yeah is not correct no so you can compare a Boolean value to be less than another value absolutely certain why is that how do we compare that you don't think a conversion could occur to an integer value and then comparison be done no alright now let us go to the group which had a disagreement so first you tell me each of the disagreements and then explain your individual reasons I have the option C and he's having option A and C A and C are wrong according to him yeah and thinking only see and according to you only see so why do you think a is correct because I don't found any problem in the expression so how would it be evaluated first that the end operation and then now the end operation be valid at first be and then be that will be very funny what is the higher priority we saw the priority you forgot to write it down the comparison operators after compiling so we have compared then and then this will be ended with B then so if I put the value of C equals to 1 then it is a proving to be correct so you think that two Boolean variables can be compared with a relational operator right whereas your neighbor thinks that it does not ok why do you see C is incorrect because it has assignment operation yes that right so what is wrong with the assignment operation I am assigning C to something it is in the right it should be in the left assignment operation no the name of the variable to which assignment is to be done is to be on the left that's the right thing ok now here is a problem if the operator assignment operator had the highest priority then this statement would still be correct because B equal to C would then be assigned first whatever be the result would be the value of that expression and that would be used in the remand fortunately or unfortunately the assignment operator has a very low priority and therefore this operation will not be done first rather all these operations will be done first now when you do these operations you will get a value on the left hand side and a variable on the right hand side now that is incorrect because you cannot assign anything to a value you have to assign it to a name so on the assignment operation on the left hand side there must only be a name nothing else if the brackets somehow came around this B and C B equal to C and that got executed first then it would still be a correct opt but as we saw the precedences that the assignment operator has a low precedence lowest in fact as compared to all and therefore this is wrong all right because his question was can I compare a real value with an integer value of course yes please remember the conversion that we said will happen even in case of relational expressions you can even say a float equal equal zero but you should never make that comparison because exact or equal equal 25 for example exact equality with floating point numbers is a very dangerous thing to compare floating point value should always be compared as less than equal to greater than equal to it so I have deliberately not commented on whether a is correct or not correct remember the choice a was incorrect according to them and they gave this reason for see they still could not give any reason so I have deliberately not answered that question that whether two Boolean variables can be compared with each other with a relational expression or not I want you to retain your curiosity and whenever in your labs you execute programs or you download code blocks on your laptops and try to give this simple expression and see what happens okay and if you can't then we'll answer this question later all right