 So, I will continue our discussions on the C plus plus features, but now we will start looking at details with a little more rigor, we will try to understand the exact rules which we will need to follow. Remember what I told you that when you write programs in a programming language which is an artificial language and not natural language and every language has defined rules of syntax that is grammar rules, punctuation rules, etcetera and any time you write any instruction in a program you have to strictly follow those rules. The semantics or the meaning of every instruction is very unique, so there is no scope for any ambiguity that is the nature of programming languages. In this context we shall first see the general program structure of a C plus plus program and then we will discuss the rules of computing. Specifically, we will look at naming conventions, we will look at how different data is represented internally in the sense of we will not be using, we will be referring to binary locations or bytes in terms of understanding how many bytes are allocated to each data type and so on. But we understand that the internal representation will be binary as far as we are concerned, we will be using decimal notation and last we will consider evaluation of expressions, we will take some programming examples at the end. So is the first rule, generally all statements in a program have to be written as per the rules of syntax and the entire program that we write is usually kept inside a single file. All of you are familiar with the notion of a file and file name. So here are some examples, p1.cpp made underscore sem underscore marks underscore analysis dot cpp. These are actually names of the files, these are not C plus plus names. Please understand that the file name of the file which contains the C plus plus program, the program will be read by my C plus plus compiler but the file name will be read by operating system. So you remember when you say C plus plus at the dollar symbol, you say C plus plus some name. You are actually telling the operating system dumbo to invoke a compiler and give that compiler my program which is contained in this file. So there is a small difference between the names that we use for the files and the names that we use within our programs. Now we have seen this but we will understand this better. Every C plus plus program contains some directives. These are instructions meant for the C plus plus compiler. These are not program statements which will solve any part of our problem that we solve but these are mandatory because these permit the compiler to know the context in which your program is to be translated to internal machine language. One statement we saw was hash include IO stream. You have seen this statement without understanding it. We will try to explain a bit about this statement. Again full understanding is not important at this stage but just the rudimentary facts about this. So this actually is a statement which tells the C plus plus compiler that in my program I am going to use input output instructions and when those instructions are executed, I will be typing in some values on my keyboard. You will have to take those bytes in which are ASCII code, convert them into internal format and vice versa on output. So actually the input that we give in this form or the output which comes out is in the form of a stream of bytes. One after another the bytes flow in or bytes flow out and this stream input output handling capability is already built into C plus plus in terms of some pre-written programs. We have not written them. Somebody has written them. Usually it is called C plus plus library. Now we may write programs which may not require anything from that library but we may on the other hand mostly write programs which will invoke those input output capabilities. It is this compiler directive which must be included in my program. Incidentally most compiler directives are required to be included at the beginning of the program file. So before you start writing your program all compiler directives should come there. So when you give this directive it effectively tells, you can see the name IO stream. Now you will probably understand that there is an input stream and an output stream and in that stream ASCII course will be flowing here and there and we want the capability to convert these ASCII bytes into appropriate internal representation or vice versa. That capability is available in the form of pre-written programs which are kept somewhere else inside the operating system, inside the C plus plus package. And when you give these directive C plus plus compiler on one hand will translate all of our instructions written in the program and on the other hand it will additionally include all the pre-written instructions at the appropriate places. Effectively the see in and see out statements that you have seen they work because of this. If you omit this you will suddenly start getting error messages like see in not defined in the scope, see out not defined in the scope. So what do you mean by that? Well you have not defined see in and see out. That definition as well as its long form instructions are all because of this compiler directive. So this is a bit further explanation. Remember that whatever we give are ASCII values and they have to be converted to internal binary form. Similarly C plus plus will convert internal binary values integer or floating point into byte stream which it will give it back to us. So see in and see out work because of this compiler directive. Are there different libraries available? Do I have to always say IO stream? We will get the answers to these questions as we proceed further in the course and we examine all other libraries which C plus plus provides. As we progress we will use some of them but this will be more or less a mandatory compiler directive in every program that we write. So here is an example on my keyboard. Let us say I type a value 238. So what goes from this is a stream first the byte 2 goes then this is followed by byte 3 this is followed by byte 8 and this is followed by either a blank or a new line character. That is how you will give input value. Now these 3 bytes represent 3 different symbols and all of them have to be typically converted into an internal format. Let us say this happens to be value of m. We have said somewhere int m and we have said C in greater, greater m. So what it means is that this stream of bytes which comes in will have to be ultimately convert and then put inside the location for m. So if m is a 4 byte location then you know that this value 238 will be converted into an internal binary format and appropriate bits will occupy this place. So that is the objective of the I O stream library and that is how C in C out will work. C out will work exactly opposite direction. Here is another directive using name space STD. This is slightly more complex. You have seen in the sample programs that we use names we say int i j m and float x y. We are familiar with these names. We had seen in a simplistic model that these are the names which Dumbo uses to tag to those memory locations. Roughly same thing will happen when C++ compiler translates our program. Now we are looking at very small programs which we write and keep them in a single file. In real life when you write large programs towards the end of this course a program may consist of say 5000 lines and it may be possible that that program has not been written by a single individual. Four or five different people have written pieces of that problem. Now it is possible that you are using some name say x to mean something and I am using some name x to mean something else. Now there should not be any confusion when I put all of these together. So if I want a single compilation run for the entire program segment written by you segment written by me there might be some method of distinguishing that this is part of say x and that is somebody else's x. Typically what is done in such large programs is there is a notion of namespace. So you can consider namespace to be a group of names and that entire group is given a namespace. There can be large number of namespaces that can exist. For example if suppose I have chosen a namespace called x space arbitrary name and I have declared in that namespace certain variables say a and b which are integer objects in that namespace. Ordinarily C++ requires that whenever I refer to a name in any instruction I should qualify that name by the namespace to which that name belongs. So if I have declared a and b as integer objects I will have to write my instructions of this kind. X space colon colon a equal to 5. X space colon colon b equal to 4 into x space colon colon a. There is a mistake there. Can you spot the mistake? Sorry? Yes. This x is not correct. It should be capital X. Remember names are case sensitive. Anyway the point I am making is if I indeed choose such namespace options and if I keep qualifying the name every time it will be a burdensome thing to type all of these long things. I would rather type a equal to 5, b equal to 4 into a. That is much easier for me to write. This is feasible if either all the names in a program belong to the same namespace which may be x space or y space or more easily I write names which belong to some kind of a global namespace which is a default namespace. That namespace is called standard namespace. And when I give the compiler directive using namespace std this one then this directive tells the compiler that look Baba I am not defining any namespace of my own. All my names will belong to standard namespace. This statement does something more than that. The moment I say standard namespace then you remember I mentioned libraries and other things. There are so many other aspects which are part of such libraries and they all have names. All those names are belonging to standard namespace. Therefore when I say using namespace std it tells the c++ compiler that if in my program other than the names which I have defined if I use any names which belong to the standard namespace please compile them use them properly. So this is a very crude and simplified explanation of this directive. The directive has much more to it and as we progress further we will discuss this again. Suffice it to say at this stage that as far as we are concerned in our programs we will always write these two compiler directors at the beginning. Hash include iostream and using namespace std then there will be no confusion compiler will take care of things. Now we come to writing of the programs. For the time being you assume that there can be multiple namespaces which could be defined by different people. If we use any such namespace then we will have to write all the names that we use in our program pre-qualified by the name of that namespace. So the example that I gave is suppose there is a namespace called xpace and I have defined objects like a, b which are integer. Then ordinarily I write in my program a equal to 5, b equal to 2a such statements will not be valid. I will have to write xpace colon colon a equal to something that is the rule of sequence. Since that is burdensome we are saying why do we want to write this? So we want to tell the compiler that I am not using any of my own namespace use the standard namespace in which case I do not have to write qualifications. So when I give a directive like using namespace std then statements such as int a, b, a equal to 5, b equal to 4 multiplied by a become valid statements. So c++ compiler can understand that the names a and b which I am choosing do not belong to any individually named namespace they belong to the standard namespace is that ok? In any case because similar doubts may still exist in the minds of many people. So please take it at the moment that this statement is mandatory. Let us say we do not understand the full implications of this statement. But let us say that unless I write this statement my program may not work properly rule number 13b of c++ whatever we do not care. Remember what I said we have to follow rules which are defined by the specified language this is the c++ rule ok. Now we come to write so in a nutshell I repeat this again every program will begin with hash include IO stream and it will be followed by using namespace std. Now when we start writing our programs we write various statements c++ provides a feature which is called grouping of statements and making what is known as the statement block. Any number of statements that we write can be put together inside a pair of braces. Whenever you put multiple statements in a pair of braces the enclosing braces define a single block and whatever statements appear inside that block are logically treated as a single statement by c++. So it is possible for me to write for example there are two different statements but logically they become one statement. In the sense that it is guaranteed that whenever my control flow in the program execution reaches this point it will always execute this statement followed by this statement. Both of them will be executed the effect will be as if a single statement. Now this notion of blocks is extremely important and when we discuss conditional execution of statements or iterative algorithms we will see how this is vital this notion. More important that this juncture is the entire program that we write is considered to be a single block. The entire program in fact that we write is called the main program. So you remember now you remember this was the structure of the program. We write an opening brass we write an opening brass at the beginning after int main opening bracket closing bracket and we write the closing brass at the end. That makes the entire program as if it is a single statement. In actual practice this entire program is treated by the operating system as a function. What is the property of a function when we write a mathematical function say for example we write f of x is equal to 2 x square plus 3 x plus 5. So what it means is x is a parameter to this function and depending upon the value of x the value of the function will be equal to 2 x square plus 3 x plus 5. The function always evaluates to a single result value. Now actually all the programs that we write in C plus plus are called functions. We will see later how we can write multiple functions in our program. But the main function is the main program that we write. It is therefore mandatory that even when we have no other functions the program itself that we write should be written in the form of a function. The first line int main something something defines the beginning of that function starting with that opening brass and the closing brass indicates the end of that. Now you remember at the dollar symbol you write something like dot slash a dot out to execute a compiled program. You remember that? So actually what the operating system does this is the operating system. This is what is dealing with you you are interacting with operating system. When you say dot slash a dot out what the operating system understands is that oh you have a executable program which I will treat as a function and I will pass control to that function. Passing control means I will say Mr. Junior Dumbo execute yourself. Now that translated program which we hypothetically call Junior Dumbo executes all the instructions. When the last brass is reached before that you notice this statement that we write is return 0. That return word means go back to the operating system. The fact that it is actually treated as a function although we are not discussed functions in details we will do that later means that just as a function mathematically can have parameters my program itself can have parameters indeed if I don't write this int main opening bracket closing bracket just like that but I write something called p here. Right now we won't do that but later on we will see what that p means. If we write p here it means that my main program itself expects a parameter. Now this parameter is not something that will be handled by input output state. We expect that parameter to come when my program itself is invoked who is invoking the program operating system. Consequently in such situations we will expect p to be passed as parameter. It is not necessarily that the function should have only one parameter could have p 1, p 2, p 3 whatever and all of them will have to be written here. Again I emphasize for the time being we will never write any such parameters. I am just trying to explain what is likely to happen. Remember whenever multiple parameters are used by a function such as f x equal to this or f x comma y equal to something x square plus something y square whatever all of that returns a single value. Actually when you say return 0 you are telling the operating system I am returning you value 0. I can actually say return 1 return 5 can I say return 7.8 why as everybody followed why I can't say return 7.8 that type of value which I return is written by us at the beginning of our program. Int main that word int actually describe the type of value which will be written. Can I write float main of course I can I can define any kind of function. But as far as the operating system is concerned it has some intelligence built into it to understand what some of the return values would mean and that intelligence is based on a function returning integer value. 0 usually means that the junior number which was executing its program has run it properly. So 0 means successful completion. That is why whenever we reach the end of the program while executing if we have reached that end it means our program is executed correctly and therefore we will say returns 0. Later on we will see when we write large programs and if there is an error condition that comes up which we can notice during the program we can say return 1 return 2. And operating system actually is capable of initiating some other action if the value return is not 0. But all that is too complicated at this juncture. So again to conclude the simplified view that we take is that a pair of braces include all statements which are logically treated as 1. The entire program that we write is actually logically equivalent to one statement. It is treated as a function. The operating system passes control to that function at the beginning and when my program execution terminates it returns control to the operating system. Is that okay? So this is what is stated in words what I just explained that the operating system can pass one or more parameters to my function the main program and when my program completes it not only passes control back to the operating system but it can also pass a value and that is what involves using a return statement with a value. Of course okay we will just stick to this. Come back to the point that we are discussing structure of a C plus plus program. What we have seen so far in this structure is a we will have those mandatory compiler directives at the beginning. B the entire program is to be written as a single function called the main function and you have to begin the program by saying int main opening bracket closing bracket opening brace write all the statements and put closing brace at the end that is the structure of my program. Now we come to the components of our C plus plus program. So this will have several computational objects int A int B flow takes are all computational objects 13.75 a value which appears in one of the statements is a computational object it is called a constant object it is a value all these computational objects when we want locations to be assigned to them where the values can change they must be given names and all the names that we use must be declared the declaration of a name is required to be made before the first use of the name. Consider this for example I have C in X then I have Y is equal to 4.0 into X where is the input statement happening at this place somewhere before that I am required to say for example flow takes. So wherever X is first used before that I must define since I am not using Y in the first two statements I am using it only afterwards it is possible for me to write this as float Y. So this declaration can come however as a good programming practice we will always write this as float X comma Y and then write all the statement. So effectively while C plus plus program syntax only requires that the name should be defined before the name is first used we will add that we will group all the names together at the beginning and we will declare all the values. Any questions on this? Yesterday there was a good question so since nobody is asking let me ask you this. We had said that before the execution begins the C plus plus compiler reads the entire program and translates it right. We had a funny exercise where I had asked you to raise hands clap etcetera you all did and then the final instruction said don't do anything and we said then that the compiler doesn't do the stupidity it first reads the entire program. The question that I was asked is that if the compiler is going to read my entire program first then why can't it figure out it doesn't matter where I declare my names even if I declare my names at the end it is required to read the entire program anyway. Why can't it collect all these declarations and then start translating right? Is a reasonable question so what is your answer? Sorry one at a time please. Yeah anyone who is saying now because his answer is because the compiler executes the program line by line from the top. You have not understood the basic compiler will never execute a program. It's not compiler's job. Compiler merely translates the program into machine instruction. Execution begins for the entire set of translated instruction when we say dot slash a dot dot. So there is no question of execution. Compiler is supposed to translate the program and we had asserted earlier that the compiler will read the entire program when it translates. The question was if that fellow is going to read the entire program anyway and since my declarations like int something float something are very easily identifiable. It does not matter where I write them. After all in this first reading it should read all of them. Assign all whatever memory locations it wants and then translate the remaining instruction. So why the C++ compiler insists that we must declare a name before it is first used. So he is saying that if we don't declare it at the beginning for example if I don't say float x here it may get confused as to what is C and C in greater greater x whether it is a floating point integer or something. But the contention here why should it bother about what is C++? Initially it should read the entire program collect all the declarations interpret those declarations make up those allocations of the memory allocate memory and put those tags then it should read again and this time it should translate only the executable instruction. No when the execution begins at that point there is nothing like assignment of locations all that has been done while translating. Please understand that int a float y all these commands are not translated. There is nothing of these translated. These commands merely tell the compiler that allocate location call it a allocate location call it x. What is translated are my executable instructions C in greater greater x y is equal to only those instructions are translated. The point is before translating them if the compiler was to read the complete program first it can definitely find out what all names I am using. And then it should read the program again this time it should ignore those declarations because it has already read them. So while this is logical somebody who defined the C++ language long time ago said I will not do this stupid Godagiri because you don't want to write all your declarations. So he made a rule. Rule number one all names must be declared before they are first used. The C++ compilers now have been written to implement this rule strictly. So if it ever finds a name that is not declared it will give you an error. Logically there is no reason why this rule should be there. But because you and I have not defined the rule somebody else has defined the rule we are required to follow it we follow. Effectively it makes the task of compiler a little bit easier. While reading the program in the first step itself it can do much more than just understanding what are the names declared etc. That's the problem. Such things will occur again and again and again. We may logically question and we should logically question why is this like that why is this like that. But ultimately we have to conclude that while there does not appear to be any logical reason for this rule just because we have not defined the language we cannot. Suppose we don't like this rule what do we have choice? Well we define a language called CS101 C++ and then we write a compiler for it. Some of you would be doing that job later. Okay. Not CS101 C++ but something else. No there is a mistake here. I don't know how this happened. This particular statement you see this statement. This statement does not belong to this line. It says comments can be inserted anywhere in a program. This should come in the next slide where it says ignored completely by the compiler. Obviously if a slide says ignored completely by the compiler we don't know what is ignored. So comments are ignored completely by the compiler. You remember how do we write comments? We can write slash slash program something or we can write slash start long comment. There are two different ways of writing comments. We have not seen one more alteration that is possible in the first type of comment. I can actually have a statement which says this statement is valid. That means on any line of my program towards the end strictly towards the end if I put slash slash anywhere compiler treats from that point onwards to the remainder of the line is a comment and it ignores that. So this way if you want to write a comment to explain the purpose of a particular instruction in your program you can do so. So this is a third variation that is possible. We are now ready to understand the organization of a C++ program. This looks familiar. You would have seen similar programs in your lab. You will see many more of course in the course of this semester. So we begin with a comment which doesn't matter. All comments are completely ignored by C++. Remember that. Hashtag include IO stream using namespace STD. No kajal on that. We have understood. What we have understood is even if we are not understood why those statements are there they have to be there. Otherwise our program is not there. Again some more comments now starts in to main. So this is the beginning of my program. Opening grass and this is the closing grass and before that they return zero statement. We now understand what these are. In between is our program. Within the program we see that I have left a few blanks at every line for all the lines which constitute the program itself. This is called indentation. So notice that the first few lines including comments start at a certain point here. When I come to writing my programs I am leaving one space, two space, three space like that. Observe that when I write my program like that it becomes slightly more readable because at a glance I can see this is the block of statements which constitute my program. Later on when we study the other control structures starting with this Friday lecture we will see how important is the indentation of this type when the program could become very long and complicated. We can understand. Usually a tab key is pressed. Tab is the old typewriter kind of notion. Whenever you press the tab key in a old typewriter the carriage will move eight spaces further. In computer tabs you can set the tab spacing by choosing appropriate option in your G edit word process, G edit text editor. So I set for example tab to three spaces because there will be multiple indentations that I may later on require. Every time you press a tab it will move three spaces further. It is merely a nice way of writing. Here are some explanations of the same program. First two are the compiler directives. Everybody follows that. The main program begins at Int men. Return zero effectively says stop program execution. So this is an executable instruction. It will be translated into machine instruction equivalent to go back to operating system. And in between are my statements in the program. Is this clear? No confusion in the names. Very simple indeed. Now we come to the names. Names are called identifiers. In fact names are galore in any program. There are certain names which are part of the programming language itself. Name space, using, return, see in. What are these? These are names. They mean something to C++ compiler. Such names are called keywords. What we are bothered about are the names that we use to denote some computational objects. The rules for that is a name must contain either alphabets a to z capital or small or digits 0123456789 or underscore character. These are the only three types of symbols which are permitted in a name. Additionally C++ says that a name must begin with either an alphabet or with an underscore. It cannot begin with a digit. Further name can be of any length. I can write 50 character name for a location where I want to store an integer number. Since large names are possible and in fact people are encouraged to write more meaningful names which will necessarily be large. C++ simply says if you go overboard and write all names which are 40 characters long, I will have difficulty in distinguishing them. So please make sure that the first 31 characters of any name are unique. So actually translators which follow this rule do a smart trick. You may use length any name. If a name is shorter, of course it would be considered in full. But if a name is longer, the compiler will simply take the first 31 character because that defines the name effectively. Keywords in C++ cannot be used as a name. So I cannot say int using, using cannot be a name of an integer location in my problem. And of course meaningful names must be chosen by us. Are these rules clear? Again why a name cannot begin with a digit? No. It is presumable to ensure that the names are English like which always become a verb. But then why a name can begin with an underscore? How would you like a name which is underscore, underscore, underscore, x, y? It is a valid name. Underscore, underscore, underscore is also a valid name. Obviously they are meaningless. By the way the convention in C++ and Unix programming in general is that the name starting with underscore are treated as internal systems name. And certain packages use names starting with underscore, underscore. This is to ensure that since ordinary mortals like us are unlikely to use such names they will never clash amongst themselves. That is the objective. So as a rule we will never start a name with underscore. But we will use underscore to distinguish different phrases of the name if there is a long one. Let's consider some examples. Role number of a student. I want to represent role number of a student. Can you suggest some names? One name. Any other name? R. Any other name? RL. Okay. RNO. We have written four or five names. What about a name? X. Well C++ compiler doesn't know that what we are storing is a role number. For it it is either an integer or a floating point value. The meaning of that name is only amongst the human being. C++ compiler doesn't care. So X is a perfectly valid, illegally valid name for even role number. However for human beings it won't make sense. Amongst the remaining names, which names do you think reflect the meaning that we have in mind more accurately? First and last. This is the reason why longer names are permitted and they are incorrect. The reason why we tend to use R, X, A, B for two reasons. One we are familiar with mathematical formulae expressions and almost all our algebraic expressions will be A plus B multiplied by X minus Y something. We use single digit symbols in algebra. So that habit carries on. The second reason is if I use long names, I'll have to do the Godagiri of typing those names everywhere. So why waste time doing that? After all compiler doesn't care. But we should remember that we should care because our programs will be read later by other people and they should understand what it says. Value of a temperature in degree centigrade we had used in our sample program, C. Perfectly finds a valid name. But can you suggest something? Temperature? Temp. Temp C. Any other name? T. I would suggest that the last two names are more meaningful. Particularly the last name is more meaningful because temp underscore temporary also technically signifies to a human reader something which is temporary. Temp is also a short form for temporary. It's not a good idea to use the word. Marks obtained in a quiz. Sorry, M. Marks, okay. Some odd name was suggested. Can you say it loudly? MKS, okay. Somebody suggested something very fancy. What was it? Mobile number. All of them are valid names. If in mobile number I stored marks at 24, 32 or 0 as my friend desires. It's all valid. Compiler doesn't care. But what is meaningful to us? How funny it would be if we say mobile number plus something, okay, is whatever. Consider you have said marks. Let us look at another example. Marks obtained in the semester end examination. Here again I could have said just marks. Marks underscore and underscore same. Would it not make sense then in the earlier context to say marks quiz are better still in our normal sense and same marks, quiz marks. Suppose I conduct five quizzes. A quiz mark is only one quiz. So you are suggesting quiz one marks, quiz two marks. If I conduct 100 quizzes then my program will really become complicated. If finally I want to calculate total marks imagine what would happen if I have 100 quizzes, two tests, one end same, one mid same. So I will have end same marks, mid same marks, test one marks, test two marks, quiz one marks, quiz two marks, quiz three marks, quiz four marks, quiz 99 marks, quiz 100 marks. Will that be a good problem? Later on in this class not much later within a couple of weeks we will learn the notion of arrays which permit us to give a single name to a collection of values. And we can identify individual elements in that collection just like we have an array elements. This is just to indicate that if we did not have such a feature it could be we could become miserable writing programs with such names. So we just conclude that names have to be meaningful. Names can be chosen by you. But when you write your programs never ever choose names which do not reflect at least some sense of the meaning of the real life problem entity that you are representing. Don't forget these names don't make any sense to the compiler. Compiler merely takes a name as long as it is unique. Ultimately it is going to push all these names as tags to the memory location. Internally memory locations are numbered 1, 2, 3, 4, 5, 6, 7, 8, 9. So it doesn't matter to the compiler. But to us who will read, modify programs, run them, again read these things matter. In C++ names are used to represent objects and values associated with names named objects can change common sense. So each object can have a value of a certain type. We also use constant values in our program 35 minus 7. These are also computational objects. But they are constant because their values don't change. If I have a name the value may change. What are the types of values? We have seen intent float so far roughly understanding what they are. There are many types. I have listed some here. Care, int, float, double, void. Void is a type which means value less. There is a name but it does not represent any value. Boole. We don't know what bool is. Boole. Have you heard of a mathematician called bool? Have you heard of Boolean algebra? You have heard of Boolean algebra but you have forgotten bool. Not very good. Bool was the scientist who actually enunciated Boolean algebra first. What is the characteristic of Boolean algebra? It deals with truth value, true or false. The bool type actually is used to represent true or false. It is internally designated as 0 or 1 but that is incident. We will not deal with that right. W care underscore t. Very funny type. Don't spend any time at all in trying to figure out what it is. We will not use it for the time being. Towards the very end of the course we will understand this and some other fancy type. But the fact is that C++ compiler does permit very specific data type which can be used. As we shall see later C++ is an object oriented language and it permits us to define our own types. These are called abstract data types which could be written as combination of some kind of the existing data. We shall see those things also later. For that time being we will concentrate on integer and fractional value, numerical value. And those numerical values are typically int and flow. Int represent integer values and flow type is used to represent fractional values including large values. Numerical values are written by us in our program or they are typed on the terminal or they are given back to us by the executable program when output statement is executed. All these values are written of this kind. 25 minus 7389 12400000. All these are valid values whenever we write them in our program. Very large and very small values can be written in exponential notation. We have already seen that. It is a standard exponential notation where we write a mantissa and we write an exponent. Now C++ permits us to write such constant values in our program and also accepts these as input. Declaration of objects – you see, C++ actually forms classification of objects. All objects of a certain class share the same character. Int is one such class. All objects of that class whether int x, y, int a, b, c, int abrakha, tabrakha all these names share one feature. They can store internally an integer value. They They can be operated upon by computational operations such as plus, minus, something. These are common characteristics. The compiler will use our declaration to allocate appropriate memory space. 1 byte, 2 byte, 4 bytes, 27 bytes, whatever. If we say int i comma j comma count comma number of tanks, we are actually defining four different objects. Each one of them will be given a 4 byte location. You understand byte? So i, for example, will have, which will be used to represent the number interval. There exists other qualifiers. It is possible, for example, to say, if I say short in s, I am telling the compiler that my values are not going to be very large. Don't allocate 4 bytes. Allocate only 2 bytes. Suppose I want to store very large integers. You remember 4 bytes actually represent the maximum capacity of 0 to 2 to the power 32 minus 1. And if those numbers are signed numbers, we lose one bit. And the capacity is hovered somewhere around 2 to the power 31. But if I have larger numbers to represent, I can say long int, let's say big. Then this fellow big will be given typically 8 bytes. 8 bytes means how many bits? 64 bits. So even if you leave aside 1 bit per side, your range increases very low. It is not necessary that these 2 bytes, 4 bytes, 8 bytes, which are explained in this example are valid for all C++ compilers. Because the number of bytes, sadly, is not a feature of C++ language. C++ language simply says integer numbers can be handled if you define them to be int. What should be the range of numbers, etc., is left to the individual compilers. Luckily, most of the compilers implement similarly. But when you examine, when you are running programs on a compiler, you should actually check what the short mean, what should long mean by giving values and checking what turns out to be computations. Integer values can be decimal numbers. They must begin with a non-zero digit. The reason is that an integer number which begins with 0 has a spatial meaning. I have drawn a line to indicate that there are notations available, which can be used while writing C++ programs, where the values which I give can be specified in octal or in hexadecimal base. Octal is base head, hexadecimal is base 60. If a number begins integer number, begins with 0, it is treated as an octal number. That is the reason why ordinary decimal numbers are not permitted to begin with 0. Not that they are not permitted, but if you write a number beginning with 0, C++ compiler assumes that the value is written in an octal form, and then it will convert appropriately. We will not be using octal and hexadecimal numbers in this course for quite some time. So please don't bother if you are worried about who is octal, who is hexadecimal. Just ignore everything that is stated in the last part of this slide. The first part is what is relevant. Floating point values. We have seen the notion of floating point. I will briefly explain the notion once again why it is called floating point. Effectively this type is used to represent fractional numbers or very small or very large numbers. Consider the first number here. If I were to write it in an exponential notation, I could write it as 0.00046E1. Is that correct? No, because E1 will mean 10 to the power 1, which is 10. So I can also write this as 0.00046E-1. I can also write it as 0.046E-2. I can write this as 0.46E-3. I can write this as 4.6E-4. Please note that mathematically all of these represent the same value. What it means is that whenever I write a value in an exponential notation, E notation as it is called, then there are multiple ways in which I can write the value depending upon where I decide to put the decimal point. I change the exponent appropriately, it represents the same value. That is the reason why this representation is called a floating point representation. You can write one of these representations. I can write another representation. The result will be same. Now, when such numbers are translated internally, you remember we said that internally all numbers are represented in binary form and four bytes are typically allocated to represent four of these numbers. What is done is this portion is used to represent mantisa and this portion is used to represent exponent. Some portion, it is not uncommon. This is a typical representation, 24 bits for exponent and 8 bits for mantisa. Sorry, 24 bits for mantisa and 8 bits for exponent. It is therefore mandatory that for the sanity of the translated instructions to work correctly, the representation of mantisa should be uniform for all numbers. What the compiler does is, the compiler puts the numbers such that the mantisa is normalized so that what is written inside the m part is an integer. For example, this will always be written as 46, but it will not be interpreted as 46. It will be interpreted to mean 0.46. Effectively, what the compiler does is that it assumes the decimal point to exist at the beginning of mantisa for any number that is written. It makes sense therefore to write the actual mantisa value, normalize such that the first digit is a non-zero digit. Otherwise, you will lose precision. That is why this is the format which is actually chosen and therefore this number will be minus. It is merely called floating point because in our representation on paper, I can float the point and write the same value differently. Internally, the number will always be translated such that the mantisa is assumed to have a decimal point at the beginning. The actual value of mantisa as written is always an integer value and the exponent also is an integer value. Of course, the mantisa and or exponent both can be positive or negative so the signed representation etc. can come into picture. I am explaining this just for you to try to understand what goes on inside. We will not bother with these at all. Please understand that in our programs if I write any one of these it is as valid as anything else. This is just to understand why it is called floating point. That is all. As far as we are concerned, we will take it to mean that the notation translates into something like this. The other part in which you represent these numbers is some very large numbers like this. Minus 1.29. What would this number mean? 1, 2, how many zeros? You sure? Large number. Can this number be stored? It is an integer number. When I try to store it as an integer value you will have a problem because the precision may not be sufficient. We shall see some of these examples when we look at the expression evaluation. The C++ language specifies the following but every compiler is free to independently implement the precision of mantissa and the range of exponent as it pleases. Minimum values are prescribed. It is the standard of the compiler that we want to represent as an exponent and mantissa. No, no. We have to assign it to a location which is declared as float. We will see that in a short while. We will see that when we look at the expression. So, these are the rules. Mantissa precision is 6 digits minimum. Exponent range is minus 37 to plus 30. Actual exponent range will be much more when you allocate 8 bits. Actual precision would be roughly around between 6 to 7 digits but these are matters of detail. Floating point objects are defined using the keyword float. So, when I say float x, y, val, radius, etc. They are all allocated 4 bytes and out of them some bits are reserved for mantissa some for exponent. This is the typical 24 bits and 8 bits for exponent but I may have need for higher precision in my mantissa in which case there is a version called double. Double is like bigger float number. So, if I say double large val then this large val will have 8 bytes allocated to it typical double the 4 bytes. Obviously the mantissa portion will be larger exponent could also be larger. These are independent things. I could have an implementation where exponent is still 8 bits and all the remaining bits are used to represent a larger precision mantissa. That is possible.