 Welcome back, in the last segment we discussed two-dimensional arrays. Now we are going to talk about command line arguments. This also uses arrays and the arrays but the arrays are not really two-dimensional. So what are command line arguments? So far we have executed our programs from the command line by typing dot slash a dot out at the shell prompt or of course we have executed them from by pressing the run button. But you can specify arguments from the command line and even if you are using the IDE, you can get into a shell prompt and then there you can run the program and at that time you can give arguments when you run the program. So for example you can type something like dot slash a dot out math followed by biology. So two words you are typing on the command line in addition to the name of the program that you want executed. So the program can get access to what you type and how to do that is the topic of this segment. By the way a dot out is just the default name given to our program after compilation by the compiler. We can ask the program to give it a different name if you wish or we can rename the file ourselves explicitly. But this is just to keep things simple that we are assuming that we are just using the name that the compiler gives to the executable program that it creates on compiling our program. So I am going to show you a program that is the simplest possible thing. So it does not do anything with the whatever is typed but it just prints and shows you what is typed. The main function earlier had the signature and main open parenthesis closed parenthesis. Now here to get the command line arguments you are going to have a different signature. So essentially your computer when it executes a dot out is going to execute a dot out or it is going to call the main function but it is going to tell the main function that oh here are these additional, here are these things that the user typed when the user started off the program. So therefore there are these additional things. So what are these additional things? Well before getting to that let me just show you the program and then we will explain it. So this is the main function and that is the only function over here but its signature is different and now I will tell you how these arguments are to be interpreted. So arc c is going to give the number of words typed on the command line by the user. So as I said when your computer starts off the main program it is asking the main function to execute and at that time it is calling the main function and it supplies these two arguments. So the first argument says how many words are there on the command line. So this is just function overloading if you will. So you remember that I can have the same name with different signatures and this is just a different signature. So both names are both ways of calling main are acceptable and if you want the program to get access to the command line arguments then this is what is supposed to be used. So I told you what arc c is and then let me tell you what this complicated looking thing is. So to understand that let us just go over what it could possibly mean or some let us do it step by step. So suppose I typed this as the declaration. What does it say? It says that x is an array of char. Now what would this say? So this would say that arc v is an array of char star. In other words each element of arc v is a char star or each element of arc v is a pointer to a char array and arc v has length arc c. So this arc c that is given is has length is the length of this array. So how many elements are there? There are arc c elements in this array. So arc v is the name of an array, it has arc c elements and each element is a char star. So it points to another char array. So I think a picture is necessary so let me draw a picture. So this is this array arc v. So it looks something like this and it has elements 0, 1 all the way till arc c minus 1 because there are total of arc c elements and what is each of these elements? So this is of type char star. So it means it is a pointer and it points to the 0th element of an array and this is the first word on type by the user on the command line. So typically this is going to be dot slash a dot o ut but of course it is going to have a null at the end as well. So this is, so this 0th element is going to type is going to point to this. The first element is going to point to an array which stores the second word type by the user with a null terminator. So let us say the second word type was math and then there was a null terminator. So let me get rid of this. So this is the second thing. And then maybe there was a biology also. So this points to another array. So biology followed by the null character. So this is this complicated looking structure that is given to you. So what is this program doing with this structure? So it is printing out arc v of i. So let us see what arc v of i is. So this is the array arc v, arc v of i is this. But what is this? This is char star. So suppose I write c out followed by some after which I give a char star value. What happens? Well that simply prints out this value, prints out whatever it points to. So this first thing would just point, print out a dot out. The rule to be used over here is that whatever gets printed out will be printed out only until the null character. So c out arc v of 0 will end up printing dot slash a dot out. Then in the next iteration, c dot arc v of 1 will end up printing math. And after that biology will get printed. So in this case arc c, if I had just typed these three things arc c would have been 3. So I have basically told you how this executes but let us just do it again very clearly over here. So arc v is an array of three elements, arc v 0 contains the address of an eight element array containing dot slash a dot out followed by null. So y eight element dot slash a dot o u t and null. So notice that exactly c plus plus will allocate exactly as much space as we want. So arc v contains math followed by null and arc v 2 contains biology followed by null. So basically when these things are executed dot slash a dot out, math and biology will get printed. So what have we studied in this entire lecture sequence? Well, we studied a way of representing character strings first. Later on we will study the string class which is nicer and safer. But as I said many of the ideas that were presented over here will be applicable there as well. And these ideas in any case are used a lot in the c language and you may encounter programs which are specially which only use the c language facilities and therefore this is something that is useful for you to know. Then we studied two dimensional arrays and basically you can extend that idea. So if I write nt a and give three, so three numbers in three square brackets then that gets me a three dimensional array. So what is a three dimensional array? So it is a collection of elements or collection of variables say a i j k. So these, you can think of these as the different names and for this, for this declaration a 10 20 30 I will range from 0 to 19 j will range from sorry I will range from 0 to 9 j will range from 0 to 19 and k will range from 0 to 29. So in all if you write int sorry if you write int a 10 20 30 you will get so 600 times 10 6000 variables. And just as we thought of a two dimensional array as organized in rows and columns you can think of a two dimensional array as organized as a three dimensional object. So rows and columns but stacked on top of each other as well. So those are also needed in many cases and they can be had over here as I said earlier the c++ equivalents will be a little bit nicer and you will see them later on. And yeah so the ideas of indexing and things like that are of course needed for the c++ versions that the nicer versions that we are going to see later. Then we saw command line arguments and these are often useful. So you may want to say that look this is the file that I want to use or rather than get some data after running the program. So by cn you can directly get it as you type the name of the file as you type the name of the executable as you start up the executable program. So this is very convenient and you should definitely write a few programs of this using command line arguments and master this idea. So that concludes this lecture as always the text has several exercises and I will urge you to solve those. Thank you.