C programming language for beginners | Inside Code | Skillshare

C programming language for beginners

Inside Code, Content creator

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
57 Lessons (2h 46m)
    • 1. Introduction

      0:50
    • 2. Set up the environment

      1:24
    • 3. Create a C file

      1:45
    • 4. Our first program

      2:18
    • 5. What is a variable?

      0:47
    • 6. Data types

      2:34
    • 7. Declare and initialize a variable

      2:50
    • 8. Constants

      1:53
    • 9. Variable naming rules

      2:06
    • 10. Create your own data types with enum and typedef

      5:14
    • 11. Boolean data type

      1:56
    • 12. Print a variable

      3:04
    • 13. Scan a variable

      5:03
    • 14. What is an operator ?

      0:47
    • 15. Arithmetic operators

      5:11
    • 16. Type casting

      2:49
    • 17. Relational operators

      4:11
    • 18. Logical operators

      5:06
    • 19. Assignment operators

      3:08
    • 20. Difference between a++ and ++a

      2:46
    • 21. Bitwise operators

      5:35
    • 22. What is a condition ?

      1:16
    • 23. If statement

      3:38
    • 24. Else statement

      3:13
    • 25. Else if statement

      3:27
    • 26. Switch statement

      2:52
    • 27. Ternary operator

      1:52
    • 28. Nested conditions

      1:41
    • 29. What is a loop ?

      1:37
    • 30. While loop

      4:31
    • 31. Do while loop

      1:58
    • 32. For loop

      3:20
    • 33. Choose the right loop

      1:46
    • 34. Infinite loop

      2:42
    • 35. Break and continue statements

      2:26
    • 36. Nested loops

      2:15
    • 37. What is a function ?

      1:24
    • 38. How to create a function ?

      4:13
    • 39. Pass by value VS pass by reference

      2:49
    • 40. Let's create some functions !

      7:53
    • 41. Built-in functions

      1:19
    • 42. What is an array ?

      1:54
    • 43. How to create arrays

      3:17
    • 44. Get information from an array

      4:26
    • 45. CourseManipulateArray

      4:19
    • 46. What is a string ?

      2:05
    • 47. How to create a string

      1:17
    • 48. string.h functions

      3:55
    • 49. Scan a string properly

      2:12
    • 50. What is a pointer?

      0:51
    • 51. How to create a pointer

      2:48
    • 52. CourseDereferencePointer

      5:19
    • 53. Pointers and functions

      3:16
    • 54. Pointers and arrays

      2:42
    • 55. Memory allocation

      7:03
    • 56. Key points about pointers

      1:41
    • 57. Conclusion

      1:11
27 students are watching this class

About This Class

Welcome to this C language programming course, say goodbye to boring 15 minutes lectures, in this course you will find:

  • Quick and powerful lectures

  • A lot of examples

  • Animations

  • Illustrations

  • A solved quiz after almost each lecture

  • Practice based learning

  • Source codes

  • Programming tips and tricks

So don't hesitate to enroll, see you in the first lecture to start learning programming!

Transcripts

1. Introduction: welcome to the C language programming course. In this course, you will find all the fundamentals off C language and of programming in general with a lot of examples animations, illustrations, captions, pieces of code, etcetera. What I want you to know is that after almost each lecture, you will find a related quiz that I really want you to do and, most importantly, read the explanation off each answer. Second thing is that I really want you to practice during this course toe. Better grasp the programming concepts we're gonna see. So don't hesitate to trust your own coat or to modify the wine I show and see what happens when you try the program. It's a very good way to learn. So get ready to start learning programming and enroll in the course. If you didn't yet see you in the first lecture. 2. Set up the environment: Welcome to this video where we'll set up our work environment to write code you can use. Not bad, but it's better to have a text editor. It helps a lot when and also a compiler that will transform our code into machine coat. So to have these two elements will download what we call an I D integrated development environment. It's a software where we will be able to write code and compile it to see the result. The one we're going to use is called blocks. It's a free I D that you can download from the official website cut blocks not, or I'll put the Lincoln description when clicking on the length this weapon will appear and here it depends on your operating system. If you have windows, click on this version. Great confessed hub off main G W. Set a point exit, then the download will start automatically. As you can see after anything that don't load and opening the I D. You will get this at the middle. You have the part where you will write code at the left, the workspace where you can put your projects files, for example, at the top you have all the software related features. For example, to save your projects to compile etcetera on at the bottom you have the logs here. You in, for example, fight information about your program execution, for example, the Arabs. In the next video, we'll create its C language files to start working. See you there. 3. Create a C file: welcome to this video. Where will create a C file to start working? So he were on our idea Cut blocks, and we want to create a file to start working. For that, you click on, create a new project than this box will appear and you select council application. Then you can go, then you click. Next. Then you true. See language at not C plus plus, and you click next after it. Give the title to your project. The one you want, for example, may and true the location in your PC, where you wanted to be saved. To be able to find that letter easily. You can put it in the desktop, for example. Then you click on next and you take this to marks for the compile. Choose Janu GCC compiler. If it's not chosen yet, then click on finish. Congratulations. You got your sea far. It's in the workspace. The workspace is at lot. The workspace is at left of the screen. There you have your project. When you double click on it, you find a folder called Sources. You double click on it to find your see file Main point C. You double click on it. And Terram, here is your file appearing. It comes with some coat. It's a basic program that we will analyze in the next video. You can zoom and designed by pressing control on your keyboard and the scroll wheel off your mouth. And when you're writing code and you want to execute it, you have to compile it. You can do that by pressing on this button. You can also do it by pressing F night on your keyboard than if the compilation is Don't successfully your programmer learn on the council as you can see this black box. See you in the next video to create our first program. 4. Our first program: Walton. This video Where will create our first program in C language? A Sad in the last video When we create a new project in cut blocks, it comes with a basic program already written it just a basic program that displays how words on the screen Let's analyze it. Even if there is a bunch of new elements for you, don't worry about it. First, we have the to include instructions here. We're just adding what we call header files to our program. This one's contain ready function that we will need later. Then you have the main function this one will contain. Our instructions were right into Maine than empty parentis is. It must be present in each program. Otherwise the program wouldn't run. So we will need the main function in our program, and inside it we ride the instructions that we want them to be executed. The body of the main function is between curly brackets. Don't forget them. And now, inside the main function, we can put instructions, and the simple program will just display how words on the screen. For that we use printer function and we write our tax between quotes like this the backslash and at the end is just to go to the new long. And by the way, print off is available in a city I or Point H. The heather were included at the top. I told you that we will need it later and after it will have an important thing. The semi colons. Almost each instruction must end with the semicolon, so don't forget it, and the last thing in this program is returned. Zero. This one tells the system that the program has been executed successfully. You aren't real oblast to write it, but it's good to know. And by this way our program is really to be compiled. For that. You can press on this button built and run, or you can press F nine on your keyboard, and this is the result it just displayed. Hello, word on the council. Congratulations. It's refreshed program, even if it's not that much, but you have to be proud of it. Don't get confused with all these new concepts like Heather's functions, instructions, etcetera. It will have enough time to understand them all. Just don't give up and follow. Well, this course see you in the next videos 5. What is a variable?: Now let's enter in the Syria things. Welcome to this chapter about variables and data types. One of the most fundamental things in programming is variables. So what is a variable variable is a storage location used to store value, so we use a variable when we want to save the value in memory to use it later. For example, imagine a variable as a box where we can store something, and each variable has an address in the memory to know where it is located. A data type because it can be an integer afloat character, etcetera and name and value. Now let's see what are the different available data types in the C language in the next video? 6. Data types: Welcome to this video where we will talk about their types. Variable can be an integer, a real number character. It's Ezra. This is why we have to precise it's data time. So let's see the different data types in C language. If you want to store in. Intra, have many choices who have charge and science are short end inside short end and inside and long end inside long and long, long and and inside long, long it. Each one has its own valley rent and memory size that you can find in this table. Link is in description. The dog Marie don't have to know them all now because the one that you will often use is the end type. The n type size depends on the type of machine you're using, but if you assume that you're using a 64 bit machine than the entire occupies four bytes in memory one bite his a bit. So it occupies 30 do bits and memory so we can soaring in the job between minus to expand 31 which is this number, and to expand 31 minus one, which is this number. We can also store a real number in memory for that who have three data types who have the flow data type, which occupies four bytes in memory. The Double data type, which occupies eight byte in memory on the long double data type, which occupies 12 bytes and memory. But you will often use the flow time. Now let's see how to store a character in memory. But before you have to know what is the asking coat? As I told you in the introduction, everything in computer is represented by ones and zeroes. So is the same thing for characters. This is why we need a coat to know. How is each character presented in the machine and one of the first use codes of the asking code. Ask E stands for American Standard Code for Information Interchange on this code contains 128 characters. It contains the digits from 0 to 9. The lowercase characters, the upper case characters, the punctuation characters and some control codes like that carried return. So in general, to store character in memory, we use the Charge data type, which occupies only one bite in the memory so we can put values between minus 128 The 127. And the value represents the ask a code of that character. Not a problem. If you didn't understand, don't get confused because we will see how to declare an initial laws. The variable in the next video. See you there. 7. Declare and initialize a variable: too much theory. Let's now create some variables. First, let's see the syntax to declare and define a variable. First, we have to precise the data type than the variable name than semicolon. That's it. Let's see an example. That's great. Variable name and far off type end. So we have to ride the data tie first, which is end than the variable name, which is var than the semicolon, obviously. So what happened here? We're just allocated four bites in the memory. Who are we can store in intra. Let's see a second example. Let's declare a variable off. Typed are So we write char, then you ride the name of the variable, for example ch So now we got another variable in our program. Okay, Now we got two variables, but what can we do with them? This is what we gotta see now. First, we can initialize the variable. We can give the first value to it that we will be able to change later. For example, we can decide to store the value 10 in the first variable we created for that when declaring the variable name must be followed by unequal side, followed by the value. We want a sign done in this case, So by this instruction, the value of our variable is now 10. We can also declare multiple variables in the same line, but they must be of the same their time and separated by a comma with a semi colons at the end. Let's, for example, declare three float variables, ABC in the same line. You can initialize if you want. So we write Float, which is the data type than the first valuable that we named a Let's initialize it, for example, to 4.5 than a comma than the second variable B. We can choose to not initialize it, then another comma than third variable. See, that's initialize it to mind. The 3.65 now a semi Colin to end the instruction. Okay, now initialize the variable, but it doesn't mean that it's final value. Who can change it later in the program, for example, who initialized a at 4.5? But we can decide now, for example, to set its value to 5.2. No problem with that, and we can change it again as many times as we want. Okay, now we learned how to initialize a variable. What can we do more? You can, for example, print it. We can use it to count something. We can start the value of a result in it and many other useful things. This is why variables are very important in programming, and we can't do much without it. So in next, videos will learn how to doom or interesting things with variables. See you in the next video to talk about Constant's. 8. Constants: Welcome to this video where we will talk about Constance. So what is a constant in the Princeton video? We said that we can change the value off variable author. Initializing it, but we can make a constant instead of variable if we decide to not modify its valley on initialized. So if you make constant, if we try to change his value after the initialization will get an Arab, let's dive into it. Now the syntax is very easy. It's the same us for variables, but we have to add council keyword at the beginning. So we have cost than the data type than the name than the initial value than the final semi Khan. And this time you must directly initialize the constant. If you try to do it later, we will get an atom. So let's see an example. For example, let's suppose you're making a game where the number of players will always before so it won't change during the whole program. Then we can use a constant named number of players initialized to four. I'll tell you why I wrote everything in uppercase in the next video. Last thing that I want to show you about constant's is that they can also be useful to avoid using in significant numbers. For example, we know that in most countries, the majority age is 18 on. Let's suppose that in your program you want that something happens where the user ages under 18. You would write if user Agius more than 18. But if you read your code again after some time, you might not remember why you use the number 18. So for that, it's better to use a constant variable named majority age initialized to 18 instead of directly writing 18 on. Now let's move to variable naming rules. See you in the next video. 9. Variable naming rules: Welcome to this video, where we will see the variable naming rules because very some rules, while naming a variable first variable name, must begin with a letter or an underscore. This is an underscore, so it can't begin with a number or another character, either a letter or underscore. That's it. Rule number two. After the first leather, you can use a number if you want, so you can use a number or letter or underscore. That's it. Rule number three. You have to know that variables names are case sensitive. It means that using a lower case letter isn't the same as using an uppercase letter. So these three variables are all different. Last rule. Your variable name shouldn't be cured with Talk about it in the president chapter. So if you're using car blocks and your variable became blue, so it's a keyword. And now let me show you a naming convention that you can use. As you know. We can't use a space character invariable name. So to join between the words and get a readable name, there is naming conventions. The most used one is a camel case. For example, we have variable named the user jumps count. But I said earlier, we can't use spaces. So the Camel Case convention is to join the words and to capitalize the first letter off each word except the 1st 1 So in this case, we would write it like this. We have other naming conventions, like the Snake case, where we put an underscore between each word instead off a space. It's as you want. We have also naming conventions for other programming elements like the constant. In the last video, I wrote the constants names with Onley uppercase letter and underscores between each to Worse because this is the convention to name a constant. All letters are uppercase and an underscore between each two words. You are not obliged to use it, but it's better to do so. See you in the next video to talk about in, um and type death. See you there 10. Create your own data types with enum and typedef: Welcome to this video where we will talk about in, um and type death. First, let's start with in, um, the Adam keyword gives us the possibility to create a new data type with a finished set off possible values. For example, we can create in an admiration off week days where we put the seven week days. So a variable off type day can take one of those possible values we put in the enemy oration. Let's implement this example. The syntax off Inam is first, we have the key word in, Um, then you have the name, then, between clearly brackets, we have the different possible values separated by commas. Let's now do our week. There's example. First, we have the key word in, um than the name Let's choose day, for example. It's better to capitalize the first letter off in, um, name. And then we said the possible values between curly brackets separated by comments. So we have Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday. Let's do a second example who assume that a difficulty can be easy, medium or hard. So we creating an admiration and difficulty in the possible values we put easy medium and heart. And if we want to declare a variable off type difficulty first you write in, Um, then the Inam name, which is difficulty than the variable name Lester's game difficulty. For example, at now we created the variable so we can initialize it to medium. For example, it can take one of the possible values Onley, easy, medium or heart. Otherwise you would get an Arab. You have to know that possible values have an index for each one. The 1st 1 is zero, the 2nd 1 is one, and the 3rd 1 is to answer one, because we start counting from zero so you can assign the index in cell of the value. So in our last example, if we initialize our variable 20 it's like we initialize it too easy, because easy, which is the first element of our an immigration, has the index zero. We can very fight with a condition like this. Now let's move to type. Tough type. Death is a feature in C language that gives us the possibility to create an AL es off a data type. For example, we're making a game where the players have different scores off type end, we can directly use the in data type. It's not a problem, but we can also use type deaf to create in Ali s name its core, which is of type. And so we will be able to create variables off type score. Let's do it right now. The syntax is that we have the cure type tough after it, the data type after it, the alias name and that's it. So to take our last example, we have the cure type death than end. Then we can choose an alias name like Score. So now we can declare variables off type score, which are in reality, off type end. Let's make two variables off type score, so it follows the same syntax. First, we have the data type, which is score in this case, followed by the variable name Let's Truce Player one score, for example. Then we can initialize if we want. We can put 100 for example, because it's an integer second variable have score than, for example, player to score and let's initialize it to 300 for example, as a set earlier, you're not obliged to do it. Type that can also be useful to shorten a data type name. If you read the table off the data type lecture, you would know that we have a data type named inside Long, long end, which is very long and exhausting If you write it each time, we want to declare a variable of that type. So what can we do is that we use type have to create a shorter al es For this data pipe you are I'll end. For example. So we have the cure type deaf, then the data type which is inside long, long and in this case that the alias name, which is you are al end. So now, instead of writing inside Long, long and each time we can dire clear, right u l l ent we can also use typed off within, um, if you remember to declare a variable off a type we created within, um, we had to ride the keyword in, um than the data type name than the variable name we can avoid having to write in him at the beginning by using type deaf. So for that, we have the cure typed off than the keyword in, um than the set of possible values that the data type name, if we do it with our enough example of difficulty, were I top tough than in, um than the set off possible values, which are easy, medium and difficult than the data type name, which is difficulty. The name comes at the end this time. Don't forget. And now we can create a variable off type difficulty without writing in, um, for it, we just write difficulty than the variable name. Then we can initialize if we want. Now that you know enough on type deaf, let's move to the next video to talk about the bullion data type. See you there. 11. Boolean data type: Welcome to this video where we will talk about the bullying data type. First, you have to know what is a bullion statement. Ah bullion statement is a statement that can be either true or false. That's it. For example, if I tell you 10 is bigger than five, it's true at it's a bullion statement. If I tell you, three is equal to six is false and its bullion statement. So we have what we call Boolean variables. A Boolean variable is a variable that can hold the value true or the valley false. It has two possible values. That's it. Boolean variables are really useful in programming. We can use them in conditions, loops, functions. It's Chitra. But the 1,000,000,000 data type isn't initially available in the C language, but we have some ways to be able to use it. 1st 1 is to use an inter jar with bull as an alias where zero represents false and one represents True. So we write type deaf and bull and now we can create valuables off tie bull. But what we want is to be ableto true and false in sound off one and zero. So a better way is to include the a suitable point age library on. By doing it, we can now directly declare a variable off tie bull and it can take the value true or false . 1/3 way to do it is by using an enemy aeration the feature we've seen in the last video. So we write type tough than in, um than the possible values which are false and true. Then name, which is bull We wrote false before True, because remember that the first element has value zero and the 2nd 1 has the Valley one. This is why we put false before true so that false take zero and true takes one. And now we can declare will variables and we can use false and true as values. So now we've ended with the bully and they're a type. And let's move toe how to print a variable. See you in the next video 12. Print a variable: Welcome to this video where we will learn how to print a variable if you remember in the first little program we've made in the introduction chapter, we use print function to print how world in the Council. Now we will use this function to print variables. You have to know that in the print of function we have to put a formative string. A formative stream can contain normal text like we did with how world it can also contain special characters preceded by a backslash. For example, to go to a new line, we use backslash an and to print variables. We have to use a form of spacey fire. A former spacey fire contains first a person that symbol followed by occurred depending on the data type. Want to print? For example, if you want to print a value of type and you're right percentage D, if we want to print a character, were right person to see if we want to print a string right percentage ass. If you want to print the value of type, float your at percentage F. You can check the lake in description to find the former Spacey fires off other see data types and after the former, that string would have to preside the value or the variable related to each former specify , respectively, separated by comments. Let's do an example. Let's declare a variable of type and initialized at five. So now, if we want to print it, were right in the formative drink. The value off our variable is percentage D on. After it you put a comma, then who wrote the name of our variable on? We close the parent Jesus, and we put a semi colons, obviously, and if we compile, we get five. Where we put a former specify rare Let's do It Now with two variables, would declare a second variable off type charge this time just as an example. Let's initialize it at lower Case A. Now in the formative string we can write. The Inter job is Percentage D. On the character is percentage. See who used percentage see because it's a character. We want to print a character, and after the former to string first, we put the value off the first former specify, which is our end. Then we put a comma. Then we put the value off the second specify which is our character. Add. We get this. If we compile who can see the result, you are not obliged to use a variable. You can directly set value. Let's art form it. SpaceIy fires in our formative shrink. Let's add a percentage. The at the percentage asked, for example. So now we have to add to values after our valuables. We can put the value eight for the in type, for example, on the value programming for the strength. It has to be between double coats, and we get this result. You can try more example in your I D to practice, because learning programming is all about practicing, not just hearing the instructor see you in the next video to see how it was kind of variable this time. In other words, how to get input from the user 13. Scan a variable: Welcome to this video where we will learn how to scan a variable in president videos. We always choose the value off the variable by ourselves. But what if we want to give to the use of the possibility to choose the values off variables? In other words, we want to true the values of variables during the execution of the program and not before . For that we have some functions to be able to do that, the one that we will often use its can't half. So let's start this Got have function uses the same principle as print. If we need to use a formative string, so we will use former specify IRS. Let's start with a simple example. For example, we can ask for the edge of the user for that we create a variable of type, and we can name it age. Now let's bring that we want the users age so we can print. How old are you? For example, after it will use the scan a function to receive the result and put it in the variable we created. So we directly put the former Spacey Fire Percentage the in this case because we will scan a variable of type and and after the former Spacey Fire, we need to precise which variable we want to modify by the user input. But wait and pretty half would just needed the value. But here you want to modify the value of the variable, so we need the address, the memorial location. So we have to add in a percent just before the variable name to give the address and the not the value. It's what we call a pass by reference. It's a lot of problems if you're confused about it, because we'll talk about it again with more details in the chapter about functions. But now, just keep in mind that one. We want to scan a simple, valuable liken it teacher or a character. We have to add an 8% before the variable. Let's go back to our example. Let's bring the variable age after the input to see the result. If we compile and to write 19 for example, you can see that the value off the variable became 19. By the same way we can scan a character are afloat, for example, we can also scan a string. I don't know if I should talk about strings, because you may be confused. But don't worry if you don't understand something, because we'll have a whole chapter about strengths. So let's declare a string. One of the ways to declare a string is to use the charter type, then the string name, then just after it, the number off characters off the string between brackets. Now we can skull the string, but we don't use the n percent because it's already an address, so we don't need it. We did not need to add an n percent. You're not obliged to understand this now. Just keep in mind that is kind of variable. Use the ampersand. Except if it's a string than we don't let's make a simple program to get the information of the user. We want to know his name, the first letter off his first name and his age. So we need these variables here. Report 30 because we assume that 30 characters will be enough to start the user's name. Now let's print and scan variable by variable. First, let's ask him for his name. Now we scanned the name. It's a string so we don't use the 1%. Then we ask for the first letter off his first name. It's a character so used the n percent, then ask for the age. It's an integer, so we use the 1% and at the end we print the information. And after it's got EFF, we put gets our instruction. I recommend you to do it because you have to know that when you end your input, your press on, enter on your keyboard. It creates a new line, and you have to know that new line is considered as a character. We've talked about it in print off its back line, if you remember, so we use gets char to receive that character and avoid giving it to the next Scott F. Now let's try our program. I'm going to give my name, then the first letter off my first name than my eight, and now we got the information sprinted. Last thing about scan, if I want to talk about, is that by scanning a string with scant half, it's gonna take only the part before the first space character so we can't scan a string with multiple words. As you can see here I worked how? Word in the input, but the string took on Lee Hello and also scan F isn't really safe. For example, here I put 30 characters as the science off the string. But imagine if the user writer string that has more than 30 characters it can be really dangerous for our program. It can provoke a buffer overflow and a lot of cybersecurity attacks used buffer overflows. This is why we're going to see all those secure ways to Scott a string properly and avoid this problem in the chapter about strength on. Also, you have to avoid two things. Writing plane tax in Scott F and scanning multiple variables in once can have function. Avoid these two things because they can provoke bugs. See you in the next video to talk about sides off and limits Point H 14. What is an operator ?: welcome to this new chapter about operators. What our operators on operator is symbol that gives us the possibility to perform mathematical and logical operations on. We will see five types off operators, arithmetic operators to perform arithmetic operations like the addition of this obstruction relational operators to be able to compare between values logical operators to be able to create bullying expressions, assignment operators to be able to modify the value off variable with different ways and finally bit wires operators to perform bill level operations. So see you in the next video to start with arithmetic operators. 15. Arithmetic operators: Welcome to this video where we will talk about their aesthetic operators. As a said in the prisoner video, the arithmetic operators are used to perform arithmetic operations. We can calculate some the difference the product, the caution on the remainder. Let's start with the first arithmetic operator, which is the addition operator. The addition operator is represented by the plus symbol. It's a binary operator because it needs to elements one from the left and one from the right, and it's returns to some off those two Oremans, for example. We have two variables A and B of type end initialized to 10 and eight, respectively. On If you create 1/3 variable name it. See, for example, and to initialize it to a plus B on your print, its value. We can see that it's 18 because a plus B returned to some off the value off the variable A and the value of the variable beat, which is 18. This one isn't hard to understand, I think, and by this way we can do the addition off more than two elements. For example, in the variable See, we can initialize it toe a plus People's 15 for example, so see will have the value 33 because a plus B plus 15 is equal to 33 now. Second arithmetic Operator. The subtraction operator represented by the minus symbol. Same thing here. It's a binary operator. We need an element from the left on one from the right, and it will return the difference between them. So the older here is important because the subtraction isn't associative. Let's do an example lets you the same variables A, B and C we worked with in addition, but now, instead of assigning the addition off A and B, we will replace the plus sign by the minus sign. So now the value off see is, too, because a minus bi return stay in minus eight, which is, to addition and subtraction our basic operations that you should know if you ever did some basic math. Now let's move to multiplication. Multiplication is represented by an Asterix, this symbol. It works a Samos addition and subtraction. We have two elements on it returns their multiplication, so if we do it with our variables A and B and we assign the value to see we get C is equal to 80 because 10 multiplied by eight is 80. But know that you can do the multiplication by sticking A and B to each other, like in Mass. Same thing for the point. You can't do a multiplication off two variables by putting a point between them, like in mats in ceiling. What you have to put the at risk. Let's move to the fourth Arithmetic operator, the division operator. The division operator is represented by the slash symbol, and it returns the result off the division off the left element by the right element. But the result depends on the data type of the elements. If at least one of them is a Florida port number, so it's off tie float or double or long double will get the full results off the division. So, for example, if we divide seven by two, we get 3.5. But if both of them are integers, we'll get an integer as a result, which is the caution of the division. So if we divide seven by two bigger three, which is the cautioned, except if we do a typecasting, as we will see in the next video. Now let's see two examples about it. If we hold the same variables. ABC, with a is equal to 10 and busy equal to eight here they're both integers. So if we calculate the division off a by B, we get the caution, which is one in this case. But if we change at least one of them to athletic point number, we get 1.25 Last arithmetic operator we're going to see is the modernist operator. This one can be new to you because you may not seen it before. Like the other ones, the modernist operator is represented by the percentage symbol. But what does this operator Duke? This operator returns the remainder off the Euclidean division off the Left element by the right element. For example, I have eight Candies that I want to share with three kids. Each kid can take up to two Candies on. I have to Candy's lab that I can divide by three. This is the remainder. Other examples. The remainder off relevant by four is three, the remainder off eight by 20 The remainder or seven by three is one. The remainder off nine by two is one. Not that we can use the model is operator on Lee. With integers, we can do it with Florida port numbers on. Also, the remainder is always greater or equal to zero and smaller than the divider. The remainder is useful, for example, to determine if a number is even or odd, because if a number model is to return zero, it means that the number is even. And if it returns one, it means that the number is odd on to take up our example off ABC. If we assigned to see the operation a models be we get the sea is equality to because 10 models eight is too. See you in the next video to talk about typecasting. 16. Type casting: Welcome to this video where we will talk about typecasting in previous videos who performed operations on variables of the same time. But what if we want, For example, toe are variable of type end with a variable off type float. In that case, one of them will be converted to the other ones there type and we have two types off conversion who have the implicit conversion. This one is performed automatically by the compiler, so we don't have to add additional code for it. But which one will be converted to the other? You have to know that the small data type will be converted to the higher one by following this tractor. So, for example, if we have in the operation afloat and an end, the end will be converted to float. This is what we call a type promotion. It doesn't do the opposite because it can cause data loss. But even type promotion can cause their loss. For example, by following the data type structure variable off type long, long and will be converted to float but long, long and can hold eight bytes while float can hold only four. So be careful about this here is an example. We have a off type end on equals to four and be off that float and equals to find 40.5. If we do the addition, A will be converted to float and it becomes 4.0. So the addition gives 9.5 second example. We have a off type end on equals 2 10 and ch off type char and equals two uppercase A. If we do the addition, CH will be converted toe end. On its value is the asking value off uppercase A, which is 65. So the addition will be 10 plus 65 which is 75. It can be useful, for example, in a program together next letter by adding one to the actual value of the character. Here is an example. Second type of typecasting is Theo Explicit conversion. We will choose the data type by ourselves so we don't have to follow the structure. For that. We add the data type that we want to convert to between parent eases before the variable, for example, who have variable A as end and equals 25 if we want to get its value converted to float while printing. We had flow data tie before it like this. So we got £5 zeros. We can also do the opposite way. For example, we have a variable be off type float that equals to 7.5 if we want to print its value converted toe end. We're right and before it like this and you get seven, Onda said earlier. Typecasting can lead to death. Will also be careful when using it. See you in the next video to talk about relational operators. 17. Relational operators: Welcome to this video where we will talk about relational operators. Relational operators are binary operators. That gives us the possibility to compare between two values. For example, by using them, we can know if two values are equal or if one is greater than the other. Before starting. You have to know that relational operations returns a bullion value. It pretends one if the relation is true and zero if their relation is false. Let's start with the equality Operator. The Equality Operator is represented by two equal signs. You have to differentiated with the assignment operator that we used to give value to a variable so the equality operation returns true if the compared elements have the same value on falls. In the other case, for example, if we put the result off, five is equal to five, we get one because five is equal to five returns. True, so we get one. But if we print the result of three is equal to six, we get zero because three is equal to sex returns false. We can also compare variables, for example, here we have the variables and be initialized to six and six, respectively. If we use the equal operator. We get true because the value of A is equal to the value of B. Now let's move to the second relational operator, which is the opposite of the 1st 1 It's the non equal operator. It's represented by an exclamation point, directly followed by an equal sign. And, as you guessed, it returns. True when the two compared, values are different on it returns false when the two compared values are equal. So if we take back our last example where A is equal to six and same thing for be on, we print the result returned by the non equal operator. We get false because A and B have the same values. But if we change the value off one of them to turn, for example, and we compile again, we get true because A and B aren't cool anymore. So the non equal operator returns true. Third operator, we have the greater than operator. It's represented by this symbol. This one returns true only if the left element is strictly greater than the right one. It means that if the left element is equal to the right one or smaller than him, it returns false. If we take our last example and we print the result off A is superior than be we get true because 10 is greater than six. Next operator in the smaller than operator, it's represented by this symbol. This one is the opposite of the president won. This one returns true only if the element is strictly smaller than the right one. So if it's equal or greater than the right one, it returns false. So if we tried in our last example, it's small than be returns false because 10 isn't smaller than six. But if we change the value of a 23 for example, and we compile again, we get true. Next operator is the greater than or equal to operator. It's represented by this symbol greater than symbol, followed by an equal sign. This one looks like the greater than operator, but the difference is that this one returns true when the two compared values are equal. This is why it's called greater than or equal to so it returns false Only one. The left element is strictly smaller than the right one. Here is the proof, with these three results Last relational operator is the smaller than or equal to its represented by this symbol smaller than symbol, followed by an equal sign. You would have guessed This one returns true when the left element is smaller than or equal to the right one. So it returns False Onley one. It's strictly greater as we can see in these examples. Now, here is a lot of examples. To better understand the relational operators you can find it in. The resource is off this lecture. See you in the next video to talk about the logical operators. 18. Logical operators: welcome to this video where we will talk about the logical operators in president videos. We talked about the concept of a bowline statement, which can be either true or false. But what if we want to? Very far, the two Bullen statements are true at the same time, or at least one of them. This is why we need logical operators who have three. A logical operators. Let's start with the 1st 1 The 1st 1 is the not operator, the logical, not it's represented by an exclamation point. It's a urinary operator, so it needs only one element, not more. And this operator reverses the logical state off its element. It's ah, print. So, for example, if we have a true statement and we add the not operator before it, the operation will return false and vice versa. If the statement is false and we add a lot operator before the operation returns true, for example, let's create a bull invariable. Don't forget to include a suitable point h and in this bull invariable, we will store the result off this bowling statement. Three is greater than two will know that this statement is true, right? But now If we add the not operator before our statement and we print, we get zero. So it's false. Not that the not operator comes before the statement had not after. And don't forget the parent eases except if it's variable second logical operator, the and operator. The logical end. It's represented by two M percents like this. This one is a binary operator because it needs to elements one from the left and one from the right. On this operation returns true Onley. If both elements are true, this is why it's called end. Let's see an example. Let's bring the result off this logical operation 10 is greater than five and six is greater than four. We get true because both statements are true. But if at least one of them was false like here, we would get false by this operator. We can, for example, verify if a number numb is greater than zero and smaller than 100 at the same time. So we have our variable lum off type end that we initialize on 55 for example, and in the logical operation we put, none is greater than zero, and the NAM is smaller than 100. We can see that the result is true because the value off NAM respects both conditions. But if we change numb to 120 for example, we get false because the second condition isn't respected, so we get false. We can also verify more statements that they're all true, not only to We can do that by putting an and operator between each two statements. For example, if we have horrible in Variables A, B, C, D, and we want to very far that they are all true. So we write a than and operator than B then and operator than see them and operator than the on this expression returns True Onley. If ABC they are true, all of them. So what's gonna happen here? The machine with evaluate statement by statement. If it finds a false one, it directly returns false without even evaluating the remaining ones. Now let's move to the last logical operator, which is the or operator. It's represented by two vertical bars. If you're using a PC keyboard, you can find the vertical by by pressing. Algae are for six. The operator is a binary operator. It returns true when at least one of the elements is true, so it returns false on Lee won. All the elements are false. For example, if we evaluate this expression, we get true. Evan is the less statement is false because the right one is true and it's enough because we need at least one true statement. So the or operator returns true when the left state minister true or want the right statement is true, are both of them and it returns false when both of them are false. It's an inclusive or this is why we accept the case when both of them are true. Not like in the English language. We can evaluate more than two statements, as we did with an operator. For that we put an or operator between each two statements. So the machine will evaluate statement by statement and really return true when it finds a true statement because it's enough. And now we've seen the three logical statements so it can make combinations with them. For example, we have two Boolean variables, A and B, and we want to verify that only one of them is true. Not both will have to possible cases either is true and these false or a is false and beast True in Cody, right? A. And not B or not A and B bounties are important here, so the whole expression is true on only one of them is true. Before moving to the next video, I want to let you know that if you are interested in knowing more about Bullen logic, I made the whole course about the subject available in you Timmy and skill share. Now let's move to the next video to talk about the assignment operators. 19. Assignment operators: Welcome to this video where we will talk about assignment operators, assignment operators, our operators that had used to assign a new value to the variable. Let's start with the most basic one that we use before the assignment operator. It's represented by a single equal sign and the left side to have variable and in the right side to have value. So, for example, if we execute this instruction the variable they will have the value. Five. So we assigned five to a. We can also do it with a variable, for example, will create variable B. Then we signed A to B, so after executing this instruction, be will have the value of eight, which is five. You can even do it with operators inside, for example. Here we create a variable see and we assign a plus B. So here see will get the value off a plus B, which is five plus five, which is done now. Imagine that we want to add value to our variable. For example, we have variable A and we want to add five to it. The first solution is to write a is equal to a plus five, it seems confusing, but not that the value of A doesn't change until the end of the instruction so we can use it in the right side and here, the value of a willing gives by five. But we haven't assignment operator that we can use in set off rewriting the variable. It's this operator represented by a plus sign, directly followed by an equal sign. So from the left, we have the variable and from the right to have the value that we want to add to it. To take our last example, we can die a clear right, a plus equal five and the value A will increase by five. So writing variable plus equal value is the same as writing viable equal to variable plus value. And we can do the same thing with subtraction, multiplication division and models. Well, right, the arithmetic operator, followed by the equal sign than the value. For example, we have the variable B that is equal to three. If we want to multiply it by six, for example, we write it like this. After the execution, the value of B will be three multiplied by six, which is 18 if you want for example. Divide the variable see by two. You would drive this. You can try your own examples to better understand how does it work. We have also the increment and equipment operators if we want to increment of variable, which means adding want to it. We can use variable equality variable plus one. You can also use variable plus equal one. But the best and shorter way to do it is to use the increment operator by writing plus plus beside the variable. That's it. We can write, plus plus before the variable or we can do it after the variable. They both will increment value, but we will see the difference between them in the next video. Same thing for the detriment operator. Instead of writing variable minus equal one, we can want variable minus minus R minus, minus variable. And I said earlier, we will see the difference in the next video. See you there 20. Difference between a++ and ++a: Welcome to this video where we'll talk about the difference between a plus plus and plus plus a If you remember in the President video are said a plus, plus and plus plus a both increment variable. But now we will see the difference between them. First you have to know that they both return value so we can write, for example, be equal to a plus plus or be equal to plus plus a. But what will be the value off be in each case? In this instruction will have to happening actions who have the incrimination off A and you have the valley return the assignment. The difference between a plus plus and plus plus a is that in a plus, plus the value is returned before the increment ation, so it returns the value. Then it increments the value of a In all the words, the assignment happens that the increment ation happens. It's like we were writing this. This is what we call a pest increment ation on in plus plus a the value is returned after the increment ation, so it increments the value of a Then it returns the value in all the words the incrimination happens, then the assignment happens. It's like we're writing this. This is what we call a pre increment ation. It will be clear with examples, for example, will have a variable a initialize to five. Now assign a plus plus to be on the print. Both of them we get a is equal to sex because we increments its value and we get B is equal to five because a plus plus first returned the value of A, which was five then it incremental it. This is why we got B is equal to five because it received the value of A before getting incremental because at the moment off assignment A wasn't incremental yet, so it was still five. But if we use plus plus A and we print, we get A is equal to six and B is a call to six because he was incriminated a. Then we assigned the value to be, which became also six second example who have a initial lost to eight. If we print a plus plus, now we get A is equal to eight. But don't forget that it got implemented after it. So it's line now. And if we print plus plus a After it we get 10 because we're incremental a again. So it became 10. Then we bring to the value and this process is the same for a minus, minus and minus minus eight. A minus minus returns the value. Then it discriminates. A press documentation at minus minus. A decree meant a Then it returns the value. Preed, increment ation. I hope you understood. See you in the next video to talk about bit wise operators. 21. Bitwise operators: welcome to the last video off this chapter. We will talk about bit wise operators, as I told you in the beginning of the course, numbers are represented in binary in the machine, and a binary number is mayor of bits and bit wise operators. Our operators that work on a bit level before. Let me remind you that a variable of type char occupies one bite, which is eight bits, so its value is represented in eight bits. And in this video, as examples, we will use to char variables and be initialized to five online, respectively. And they're represented like this in binary in eight bits. Let's start with the bit wise, not operator represented by a tied like this. This one is a urinary operator. The operator will just return. It's operated with the reversed values of bits. For example, if we use it with our variable A, which is represented as 00000101 the result will be 11111010 in buyer E zero. Bn rotation here is just used to precise that this is a binary number, but this result can be interpreted by two different ways. We can decide to interpret it as a sign integer, and in this case the result would be on twos complement. And if we converted to decimal, we get minus six on. If we decide to interpret it as an inside integer than in this case, the result is in binary on. If we converted to decimal, we got 250 second between. Its operator is the bit wise, and it's represented by a single 1%. Not like the logical end. This one is a binary operator and this operator HCA pies for each bit one. If the bit off both our parents is one and zero, otherwise on it returns the result. So, for example, if we use it with our variables A and B, it will check bit by bit. And it writes one if the bit off a and the bit of B R one at that place. Otherwise it right zero. As you can see with this animation here we have zero because both are zero same thing here . Same thing here. Same thing here. Here the bit of B is one, but it's not enough, so it puts zero same thing here because they must both be one same thing here on in the last one, right one, because both of them are one. So this is the result, which represents one in binary. Third operator is the bit wise, or it's represented by a single vertical bar. Not like the logical or this one is also a binary operator on this operator. Comprise for each bit one if at least one of the ah Prince bits is one at that place, so if we use it with our variables A and B first, we have zero. Same thing here. Same thing here, Same thing here and now we put one because the bit off B is one and it's enough. Same thing here. The beat off A is one, and it's enough. Here we put zero, and in the last one who put one because at least one of them is one. So this is the result, which represents 13 in Via Larry. Next operator is the bit wigs, or which is represented by a single car. It like this, this one could pies for each bit one if only one of them is one. Otherwise it complies zero. If we do it with our variables A and B first we have zero because both are zero Same thing here. Same thing here. Same thing here. Now we put one because only the bit off B is one same thing here because on Lee, the bit off a is one. Here we put zero and in the last one you put zero because they are both one. And we said that only one of them must be one. And here is the result, which represent 12 in boundary. Next operator is the left shift operator. It's represented like this. This one returns the left operate and with bits shifted by the value off the right operate to the left. For example, if we decide to gather value off A with bits shifted by two positions to the left, we write it like this. This is the result which represent 20 in binary. If we decide to get the value off, be with bits shifted by one position to the left. We write it like this on This is the result which represents 18 in binary. But be careful. We can have a buffer overflow if we shift too much to the left, so the number off bits wouldn't be enough to support the result. Less operator is the opposite of the present. One is the right shift operator represented like this. This one returns the left a print with bits shifted by the value of the right operate to the right. This time, for example, if we decide to get the value of A with bits shifted by one position to the right, we write it like this, and we get this result, which represents two in binary. If we decide to get the value off, be with bits shifted by one position through right, we'll write it like this. This is the result, which represents for in binary. Not that you can use the bit wise operators except the 1st 1 assignment operators like this . That was bit wise operators. It's not a problem if you didn't understand everything. This ones are the most important wants as a beginner. Check the resource off this lecture and see you in the next chapter to talk about a very important thing. Conditions 22. What is a condition ?: new chapter conditions. As humans, we frequently make decisions in our daily life, and these decisions are generally based on conditions. For example, you may say if it's cold outside, I wear a hoodie or if I have enough money, I visit a new country. Let's analyze the first example. We can divide it in two parts. The left part, which is the condition. It can be either true or false. This is what we call a bullion statement. On the right part is the action. So by saying this, you will first verify the condition in all the words you check if it's called outside and if you find out that is true, you will execute the action which is wearing the hoodie. And if you found out that it's false, you won't execute the action. And this process is the same of the one we use for condition in programming. We have a condition and we have instructions that will be executed or not, depending on if the condition is true or falls and we can make more complex conditions. For example, when we have multiple cases or when we have multiple conditions, we'll see all of that in the next videos. So see you in the next video to talk about the if statement 23. If statement: Welcome to this video where we will talk about the if statement. Now that you understood the concept of a condition in the daily life, we will implement it in programming. Let's see the syntax. The syntax of a condition in C is very basic. You have the key word. If followed by the condition in parentis is and then the instructions between cooler brackets and these instructions will be executed on Lee. If the condition we put between parent is this is true. Let's uses Shima to better understand how does it work? Here you have a condition. We said that it can be other true or false. So if it's true, we execute the instructions, then we move to the code that comes after the condition. And if it's false, with directly moved to what comes after condition without executing the instructions and because an example is better than 1000 words, let's see examples. We start with a basic one. Let's say if 10 is to pair than five, print condition is true. So here, what's gonna happen? The computer gonna evaluate 10 is to pay more than five, and if it's true, it will print condition is true. We all know that in fact, Tan is bigger than five. So when we compile regarding council condition is true and we're not obliged to put on Lee one instruction, we can basically put an infinite number of instructions. And if we change the condition and make it false, for example, five small than two and we compile, we get nothing because the condition is false so it didn't print. You can also put variables in a condition. For example, let's make a program that gives the absolute value off a number. The absolute value off a number is the distance between him and zero, and it's always positive. So the absolute value of five is five, and the absolute value of minus five is also five. It's like we're removing the minus sign. So what we're gonna do is that first to get a number from the user and then if it's negative, were multiplied by minus one, so it becomes positive again. Take some seconds to try to make the program. If you think you're under suit, let's start now. First we need an integer variable. Let's name it number. Then we tell the user to give its value. And now that we got the value, we can put the condition. If the number is small than zero, we multiply it by minus one on after it were printed to see the result. Let's compile now. For example, if we give six would get six because the condition is false. And if we give minus three, for example, we get three because the condition is true. Know that if you have only one instruction in your condition, like here, you can't avoid using curly brackets so you can put everything in one line, but only if you have a single instruction. If you have two or more and you don't use brackets, the condition will take on Lee the 1st 1 You also have to know that you can use the logical operators we've seen to use multiple conditions. For example, if you want to know if a number is a multiple of three and five at the same time, we just put if number more three is equal to zero and number mod five is equal to zero. Okay, with the if statement, we executed the instructions if the condition is true, but we did nothing if it's false. What if we wanted to execute specific instructions? If the condition is false, this is what we're going to see in the next video. Do the quiz that comes after this video on See you in the next one. 24. Else statement: Welcome to this video where we will talk about the else statement. In previous video, we used the if statement to execute instructions if the condition is true, but now we will learn to execute instructions in the other case. One. The condition is false. Let's take back our first example. We said If it's called outside, I wear a hoodie on what if it's not called outside? We can say if it's called outside, I wear a hoodie else I were assured here would choose to do in action in each case. Now we will implement the else statement in C. We just have to write else and then the instructions between curly brackets and same US. For if statement. If we have only one instruction, who can avoid using Cockney brackets if you want, But know that we can't use l statement without having an if statement just before otherwise , we would get an error. Let's take an example. We will make a program to see if a person has the majority age or not. Yet for that we need a constant variable named majority H, the majority ages 18. We choose the constant variable because the majority age won't change. And now we need a variable age to get the edge of the user. Then we ask for the age. Now we made the if else condition. A person has the majority age if her age is equal or greater than 18. So the condition is if ages equal or greater than majority age. We print you have the majority age, and now we use the else statement to print. You don't have the majority age, and if we compile and we give a number, for example, 27 here the condition is true, so we have the majority eight. And if we choose a number, for example 13. The program executes the instructions off l statement and we get you don't have the majority age. And obviously you can't avoid cola brackets in both because we have only one instruction in each. Statement on here is a little shima for what happens in if else who have the condition. And if it's true, we execute these instructions and if it's false, we execute these instructions. But in both cases after it, we moved to what comes after second example, we want to check if a number is even or odd. We know that a number is even if it's multiple of two. So first we got a number from the user, and then we tell if it's even, are all depending on the number. So if number Mateu is equal to zero footprint that it's even elsewhere, print that it's art. We can try compiling if we choose for we get even. And if we 23 who get odd, just an example before moving to what comes next, you have to know that the if statement and the else statement can't be executed together. It's one or no there. It means that if we execute the instructions off the if statement with directly jump to what comes next in what I have done Until now, we had on Lee two cases. The case where the conditions drew and the case where the condition is false. That's it. What if we wanted to have multiple cases? See you in the next video to talk about else. If statement 25. Else if statement: Welcome to this video where we will talk about the else if statement in president videos we used condition, toe handle only two cases when the condition is true and when the condition is false. But we can do more. For example, you may say when I'm on my phone. If I want to watch videos, I go on YouTube else. If I want to discuss with France, I go on a messenger. Else I go on instagram. So what's gonna happen when you're on your phone? It will first check if you want to watch videos. If it's yes, you go on YouTube. And if it isn't the case, he will move to the second case. You will check if you want to discuss with friends. If it's yes, you go on messenger. And if it's no, you're going instagram. Here we introduce the else if statement who used the statement when we want to add a new condition, if the 1st 1 is false and we can put any number of else if statements were not obliged to put only one, let's see in second example toe understand? Let's suppose you have a shoes factory that those wholesaling so it sells in the large quantity, and you want to set the unit price depending on the quantity. For example, if the customer buys less than 30 shoes, the unit price is $100 else. If he buys less than 50 shoes, the unit price is $80 else. If he buys less than 75 shoes, the unit price is $60 else. The unit price is $50. So let's and the last this. We have four cases. We will check the quantity, and we will evaluate the condition by condition until we find the true one. Let's move to the I D to implement this, the syntax off else if statement is nearly similar toe if statements one. We need the keyboard else if than the condition between parent eases that the instructions between cooler brackets that you can avoid if there is only one instruction. So let's start. We have two variables. Quantity and units price. Now let's get the quantity from the user. We moved to else. If now we start the conditions, we said if the quantity is less than 30 unit price is $100. Now we move to else if asked if quantity is less than 50. Unit price is $80 Else if quantity is less than 75 unit price is 60 else unit prices, $50. So what did we do here in code? First we use the if statement we must start by f. You can start by else if directly or else. Then we used our else. If statements here we used to But we could use more than at the end. We use the else statement. I know that you're not obliged to use the else statement. Same thing for l stiff on at the end. We will print the unit price for the user. Let's now execute this program. When we give the Kennedy, the program will execute the statements line by line. For example, if we give 43 we get unit prices $80 if we give 90 we get that unit. Price is $50. I hope you understood the else if statement well, try to do your own programs. Don't limit yourself to the examples I give and see what happens. Now. Let's move to the switch statement. See you in the next video 26. Switch statement: Welcome to this video where we will see the switch statement. The switch statement is just another way to set multiple choices. Depending on the value of a chosen variable. It means that we choose variable that inside the body, we put the choices. Let's see the syntax off. Switch statement. First you have the key would switch than in parent eases. You put the variable, we put a variable, not a condition. Be careful. Then. We have the body between curly brackets. Inside, we will put the different cases. So to add a choice, you put the keyword case than the value. It must be a value, not a variable than two points. And then you put the instructions that you want them to be executed. If the variable you put here has this value and at the end, you have to put the keyword. Breck, don't forget it. All the wars, all the cases would be executed. Let's add another case. Same thing to have killed case than value than two points than instructions than break statement on. We can't continue like this by putting any number of cases we want. And at the end, you can use the key word default to said the instructions for one of the variables value doesn't fit any case. It's like the else statement. So you put the kill default than two points than instructions and then break statement. Know that you're not obliged to use default. Now let's see an example. Let's say, for example, you're creating a council game and you want to give the user the possibility to choose inaction When launching the game, you can choose to start a new game, continue the previous one, modify the settings or exit the game. We have four choices, so let's start. We need a variable named action. Now let's show the choices to the user so he can choose. We'll have printed for New Game to continue last game, three settings and four exit, and now we scan his choice. Now we can start our sweet statement, so the variable is action. Then we have the case where action is one. We print that he started a new game and you're Breck, obviously case to were praying that he is going to continue the previous one, and we break case three. He goes to the settings on case for exits the game, and obviously, in a real game there would be real actions, not just printing. And now we can set the default statement. If he gives us a choice that is neither one or two No. Three or four. So we print that. There is a choice error, and here we finished our switch statement. You can execute it on your machine and try different choices. You can also modify things to see what happens. Don't hesitate to make your hands dirty. Now we can move to the turn every operator. 27. Ternary operator: Welcome to this video where we will talk about the Turn Eri operator. So basically the turn. Every operator is the only operator that takes three elements, and it's another way to express a condition. So let's see the syntax hair. You have the condition, then we have a question mark after it comes the result. If that condition is true, then you have comma and then you have the result. If the condition is false and you have semi Colin, obviously so let's see some examples. For example, you have two variables A and B, and you want to find the maximum between them. For that, you have to compare A and B by using if statement, we would write it like this. But here it's better to use. Turn Eri operator by writing this. The condition is that a is bigger than be if the condition is true. So we assigned the value of A to Max else. We assigned the value of B second example. Let's suppose you want to print, fail or pass, depending on the average. On the condition to pass is to get an average greater than or equal to 50 with if statement we would write it like this, but by using Turn Eri operator, we will print a string. On this string will be the string returned by the tannery operator, so the condition is average is greater or equal to 50. If it's true, the printed string will be passed. If it's false, it will be fell. Hey r two output examples. Be careful while using the turn. Every operator, because putting long expressions in it would provoke a bad readability. In that case, use if else statements in step see you in the next video to talk about the nested conditions. 28. Nested conditions: welcome to this video where we will see the nested conditions in previous videos, which said that the if statement has a body and inside we ride the instructions that will be executed if the condition is true. But what if in those instructions, we put another if statement like this, this is what we call nested conditions. Let's directly see an example. Let's suppose you're running a small restaurant and in the menu we can find main dishes, and this is in my conditions. You have cheeseburger and you have chicken wings. And in deserts you have fruit salad, banana split and chocolate waffles. So when the customer wants to order, you will first ask him if he wants a mandate or desert, and inside of each case, you will ask him for the dis choice and you will add a nested conditions. Let's start so first to ask mandates for desert. Then we have two cases inside of each one. We print the available dishes to get choice, then the other nested. If here we will just print the order dish. Here are some output examples, but we could do more. We could even add another nested condition so we can get message conditions on deeper levels. Just be careful on the syntax and the brackets because you have to close them all in the right way and you can do the same thing with switch statement and turn Eri operator. So this is the end of this chapter. In the next chapter, we will talk about loops, another important programming concept. See you there. 29. What is a loop ?: new chapter loops. Imagine that you had to print numbers from 1 to 100. Imagine if you had to write. Print one print to print three print for until you're right 100. It would be really horrible. This is why, when they lose to repeat in action before diving into it, let's analyze this sentence. I it again, while I'm still hungry. What does it mean? It means that I will repeat the action off eating until I'm not hungry anymore. We can divide the sentence in two parts the left part, which is the action on the right part, which is the condition. The condition can be either true or false. So while our condition is true, which is being hungry, we repeat the action which is eating in all the words. We repeat the action off, eating over and over until our condition isn't true anymore. So before eating again, we check if the condition is still true. And if the condition became false, we just stop eating. Our last example represents the definition off Lupin programming loop is just the repetition off some instructions. While the loop condition is true and in the same language will have three types of loops. The while loop the do I loop and the for loop that we will see in the next videos. You have to know that the difference between if statement and the loop is that the if statement will be executed zero or one time depending on the condition. But the loop can be executed any number of times. See you in the next video to talk about the while loop. 30. While loop: Welcome to this video where we will talk about the wild hope The world Hope is one of the three types of loops in the C language. It has two components, the condition and the instructions. Before driving into the syntax, let's see how the while loop works. Who represented using this Shima? First we evaluate the condition. It's a bullet expression. So we have two possible cases. Drawer Fels won. The condition is true, will move to the body of the loop and we execute the instructions. Then we go back to the condition and we evaluated again. If the condition is true again, we do the same thing. We execute the instructions and we evaluate again. If it's true gun same thing and we can keep going as long as the condition is true on if the condition is false, we just moved to the code that comes after it. That's it. So let's see an example. For example, we want to multiply a number by two while it's small than 10. For that, we use an integer variable named the Numb, and we initialize it toe one. So now we can start executing the loop. What is the condition here we said We repeat the multiplication, while numb, is smaller than 10. So the condition is numb. Is smaller than 10 on what is the instruction? The instruction is to multiply Number two. Let's start the execution. We valued the condition. We have no miss. Actually, one is. It's more than 10. Yes, So we execute. The instruction were multiplying number two and it becomes too. Now we evaluate the condition again is to smaller than 10. Yes, we multiply. Now becomes four is for smaller than 10. Yes, we multiply. Now becomes eight. Is eight smaller than 10. Yes, we multiply, Not become 16. Is 16 smaller than Tun? No, it's not. The condition is false. So we ended the loop and we just moved to the code that comes after the loop. Now let's move to the I D to implement the while open. See its syntax. The syntax off while loop is very simple. First we have the cured while then in, Parenti says we have the condition. Same was for if statement and then we have the body of the loop between cola brackets where we put the instructions that will be repeated but same us. For if statement. If the body has only one instruction, we can avoid using cola brackets. Let's now take our example and implemented in code. First we have the variable, um, initialize to one on the condition waas number is smaller than 10 here is it. And inside the body we put the instruction now multiply by two. Now let's bring the final result here we compiled and we got 16. Let's just bring the value off Numb in each execution of the loop Here we got 1248 16 because Luke got executed four times before the condition One false second example will want to print the expression roof executed five times for that will use a variable named counter To count the number of times we executed. The look on loop will stop when the counter reach five. Take some seconds to guess What is the condition and what are the instructions of the body ? As we said, the condition to continue looping is that the counter didn't reach five yet so counter smaller than five. The instructions are printing Glueck executed on obviously implementing the counter. If we don't increment the counter the loop will be executed infinitely, and this is what we call an infinite loop. We will talk more about it later. We can also print that the loop is ended after it. And now let's execute to see the result. As you can see, we looked five times, and if we decide to see the value of the counter after loop, it will be five. Before moving to the next type of group, you have to know that it's possible to have a case where we don't even enter in the barrier of a loop. It's when the condition is false, other beginning. For example, if we have this loop will have an is equal to 10 on you have while on its more than five who print loop get executed. If we compile, we get nothing because we didn't have a enter to the loop because the condition on its more than five is already folds are the beginning. See you in the next video to talk about the do our loop 31. Do while loop: welcome to this video. Now let's talk about the do our loop, another type of loops in C language. First, you have to know that the while loop and the do a loop are very similar, but not totally. The main difference between them is that the wild value is the condition before the first iteration and the door loop evaluate the condition after the first situation, it means that even if the condition is false at the beginning, the first iteration off do a loop will be always executed, as we can see in this Shima. So we execute directly the instructions. Then we evaluate the condition and if it's true, we go to instructions again. And if it's false, it's the end of the loop and we moved to the code that comes after now the syntax of very basic syntax. We have the cure do, then followed by curly braces where we will find the instructions. Inside is the body of the loop and after closing the body we have the key word, while followed by the condition between parent eases and then we have the semi colons at the end. Don't forget it, otherwise you will get another on. As you can see, the condition comes after the instructions. Now let's taken example to show the difference between while and do a loop. Let's take this example wrote in both loops. First with dual do print off, we enter the loop while five is smaller than two on obviously five. It's more than two his faults. But when we execute, we can see that we get that we enter the loop because do ill executed the instructions before knowing that the condition is false. But if we do the same program, but with while loop get nothing in output because the loop verify the condition before and found it false, so it didn't execute the instruction off printing. I'll put a link below to an instagram post about this, and now we can move to the next type of loop, which is the for loop 32. For loop: Welcome to this video where we will talk about the third and last type of loops in C language named the for Loop before told him about it. Let's just analyze a while loop that prints loop executed 10 times. First we need a variable. Consider, doesn't it? Aerator and initialized to zero. Then we need the loop. The condition is that I is smaller than time and inside the loop you print loop executed and then we increments I Otherwise we would get an infinite loop. So the elements we use are the initialization, the condition, the instructions on the variable update. What if I tell you that there is a loop that makes it possible to ride the initialization, the condition and the update in one single line? It's called the for loop. Let's see its syntax First we have the key word for Then we opened parent eases. Now we have three elements will have the initialization than you have semi colons. Then you have the condition than another semicolon. Then we have the update, then recalled, the parent eases and then we have the body of the loop. We can represent it with this Shima initialization than condition. If it's false, it directly stops. If it's true, we do the instructions, then we do the update on we go back to the condition to see if there is another iteration to do. We don't initialize each time. The initialization is don't on Lee at the beginning. Let's use it for our last example. Brings 10 times Luke executed. The initialization is the variable I initialized to zero. You can declare it outside the loop. It's as you want than in the condition we have I, a small Anton on in the update to increments are so I plus plus on in the body will print loop. Execution on the update will happen at the end off each iteration when the program arrives here and when we execute, we get the same output as for the while loop. In the next video, we will learn how to true the require type of floop in different situations. But before there is some points, I want to clarify first, same as the while loop. The full of verifies the condition at the beginning, so if the condition is false, it doesn't even enter, and it just moves to what comes next second thing were no obliged to increment in the update. We can, for example, at two or three. Or as you want, you can also discriminate. You can multiply, divide. It's as you want, so you're not obliged to go from zero to end. You can start wherever you want. You can also start from the end. For example, you can print numbers from 0 to 10 but in descending order. So you start a 10 and you're document I each time until you arrive to zero third thing. The syntax of followed can be confusing. Other beginning, but you will get used to it. By the time as I told you in the beginning of the course, don't hesitate to try things you thought about in programming. For example, if you want to know what happens in a certain situation, just coat it and execute and see what happens. And if you don't understand why, just search on the Internet. Take the habit to search on Internet for programming. Now let's move to the nuts video 33. Choose the right loop: Welcome to this video. Now that we've seen the three types off Loops in C Language will have to know which loop to choose, depending on the situation. But first you have to know that it's not a problem if you don't do the right choice, because the three types do the same thing looping so you can do the task you want with anyone. Choosing the right one is just a question of convenience. Now let's talked. We started the full in general. We use the for loop when we know the number of iterations we will do. For example, if you want to execute something 10 times or 20 or 50 or any other finnic number of repetitions, you choose the for loop. And if you don't know the number off repetitions and you want to very far the condition of the beginning just through the wild Hope, for example, you want to divide an integer by two until it reaches zero. You just use wild because you don't know how many times it will divide, and you want to verify if it's not already zero third group the Do I look, we generally choose it if we want to make the first iteration, and then we verify the condition because that iteration will effect on if we continue looping or not. For example, you want to get a number from the user that is between zero and 10. You must do the first iteration to see if you continue or not. You can't verify the conditions at the beginning because he didn't give you any number yet . So you wait together first number, then you see if it's a valid number or not. We finished our three loops, and by getting experience and understanding them, you will easily know which want to choose in the right situation on the want to be confused about it. See you in the next video to talk about infinite loops. 34. Infinite loop: welcome to this video about and if it includes, before moving to the definition, let me ask you a question and old percent examples we've seen the condition we put became full sooner or layer and the loop stopped. But what if the condition with Putin never becomes false? In other words, the loop never stops. This is what we call an infinite loop. An infinite loop is just a block of instructions that loops endlessly because the condition off the loop never becomes false, so it never stops on. We have intentional infinite loops and you unintentional wants because sometimes you want to have an infinite loop intentionally. For example, in an endless video game where we want to have a new game just after the president one ends . So let's see how to build an endless loop. Before this, you have to know that in full loop were not obliged to fit all the three elements. We can let them blank, for example, if our variable is already initialized and we don't want to initialize it again. We just let the initialization part bunk. But we respect the syntax. We don't for gather semi colons or if we don't want to update the variable after an alteration. We let that part blank like this. So if you want to make an endless for Luke, we can just write this. Who led the three elements? Black on This will run forever or if we want to use a while loop. We can write while one, because one is violated to true. And in fact, true will always be true. Or you can put a condition that will always be true. For example, why five is begin entry or while Tennesee coltan. It's as you'll and you can also have an infinite loop. You unintentionally. This is the one that we want to avoid and it occurs. One. We don't make sure that the loop will end. We have common mistakes, for example, were initialized the variable inside like we did in this loop. In each iteration, I goes back to zero, so we will never reach the limit or, for example, in this loop who have I initialized on zero and decree Menting on the condition says that I must be smaller than 10. This one will always be true or the most common mistake. It usually happens in while or do while it's one we forget to increment the counter. Remember the example we did in while of video the want to print five times the loop executed at the end of the body of the loop? Who implemented the counter? But imagine if we didn't the counter would re always zero and would never reach five to stop. I hope he understood infinite loops. What if I tell you that there is a statement that directly stops a loop? Evan, If the condition is still true, we'll see that in the next video. 35. Break and continue statements: Welcome to this video where we will talk about the loop control statements, break and continue. What if I tell you that you can immediately stop a loop? Evan, if the condition is still true, yes, it's possible. It's by using the statement. Breck. The syntax is just the cured back, followed by a semicolon. That's it. It's generally used with condition. It means you can put in if statement in the loop that will break the loop. If it's true on move to code that comes after, let's see some examples. For example, we decide to get five numbers from the user, but we also decide to stop if it gives a negative number. Evan. If we didn't reach five numbers yet, so the card would be like this will have a finnic number off repetitions, which is five. So we choose the for loop and inside the loop after it given number will verify if it's negative. If yes, we break the loop and we print that we broke the loop. Now let's make some tries for it. We compiled and we give numbers to the program. If we give five positive numbers, that loop will run normally But if we decide to give a negative number, hears it. We got that. We broke the loop and it stops even if we gave less than five numbers become also used. Brecken Infinite Loops. Remember that I told you that it's possible to stop an infinite loop. It's by using Breck like this. Now let's move to the second loop Control statement. The continue statement. The continue statement just skips. The current iteration is generally used with condition. Let's say, for example, you want to print numbers from 0 to 10 but you don't want to print the number four. You just put the condition. If I is equal to four, continue and you put it before all the instructions, obviously, or if you want to escape the numbers that are a multiple of tree you can write. If I'm or three is equal to zero, continue here. You won't get multiple. Three. As you can see, you may think, Why don't we just use conditions? Yes, we can avoid using continue. But what if you had a lot of instructions? Putting in continue statement is more intuitive and shorter because it's a one line statement now that we've seen break and continue statement. I want you to take the quiz that comes after this video to fully understand, break and continue statements and see you in the next video to talk about Nestle's. 36. Nested loops: Welcome to this video where we will talk about NASA lobes. What if I told you that you can put a loop inside a loop like we did with conditions? It's possible it's called Nassib Loops on. We will have outer loop, and inside we will have an in a lube on. It's not a problem if they aren't of the same time. We can, for example, have a for loop inside the wild. So what will really happen in each iteration off the outer loop in a loop will bury executed from the beginning. An example is better to understand. For example, we will repeat the outer route five times on the inner loop three times and inside repent the values off i n g. The operators off outer and inner loop perspective to see how is the program working? We can see that in the first iteration, we got 000102 than G arrived to three. So the in a loop and it so we moved to the next iteration off October 1011 Want to in a loop and it again next iteration off outer loop 20 to 1 to two and so on until the outer loop ants and this is what happened. We can clearly see that the in a loop got executed 15 times, five times three, which is 15. A good exercise to practise on acid loops is the star patterns. For example, if you want to print a rectangle with stars, we use nationals. First we get with and like from the user than we use NASA loops. Let's drive this program. We have two variables, width and length that we will get from the user by using dual loops to verify that the input is positive. And now the outer loop represents lights. So we put the with on the inner loop, represent the Collins. So we put the length and insider print the star, and after each line we put a line breath to start a new line, and now we compile. If we choose with three and Life six, we get this rectangle. Try to do the quiz that comes after this video to practice on it, you have to know that lasted loops aren't limited to Onley tubes. You can basically use any number of loops you want, and here we've ended the chapter about loops. See you in the next one 37. What is a function ?: new chapter functions. Let's imagine that in your program you will frequently convert numbers from decimal to binary. Imagine that each time you wanted to do the task, you would have to write the necessary code for it. It would be really annoying, and your code would be unnecessarily long. So to avoid this problem, there exists in programming a solution, a kind of magic tool, a machine that would perform the task every time that you need to. It's called a function, and the function is just a block off instructions that perform a task when you call it. So to take our last example, we can have function that converts a number from decimal to binary, and we would call it in our program each time we want to convert a number from decimal to binary, for example, here we call the function three times functions have many uses. As we said earlier, it avoids rewriting the same instructions each time and also the fact that we can reuse them as many times as we need in our program on most importantly, it gives us the possibility to divide our coat into small functions instead of having a big single amount of code. So it improves irritability, understand ability and meant ability off the coat. Now let's see what you need to know to use functions in the next video. See you there. 38. How to create a function ?: welcome to this video, where we will learn what are the properties of a function and how to create one first to have the return type. What is the return type? You have to know that the function can return an output. For example, if you make a function to calculate the square off a number, the square will be the results. So the function will return that square. So we have to precise the data type of that result. For example, in torch are something like that, but we can decide to not return anything. For example, if you make a function that prince how world it won't return anything, you aren't waiting for results from it. So we have to use the keyword void. We will see that in the same tax. Then you have the function name. Same was variables. Each function needs its own name on. That's obvious on the function. Naming follows the same rules as variables. Then you have an important packed the parameters also called the arguments. What are the parameters? The parameters are some data that the function can use to perform its task. For example, if we want to make a function that calculates the square off a number. We will have to give that number to the function so that it will be able to calculate its square if we compare it to a cook chief barometers, I like the ingredients would give to the cook shift so that he can cook by using them. Then we have the instructions that the function will execute to do it's desk and then we have eventually the return statement. If the function returns something, we must have a return statement. But if the function returns nothing, the return statement is not obliged. When the return statement is executed, the function directly ants, even if there is instructions after the return statement. Now let's see the syntax. So the syntax off a function in C language starts with the return data. Type the data type of what your function will return. If it will return and end here. We right into if it will turn afloat. Here we write throat and so on. And as we said, if it returns, nothing will write void. Then we have the function name and now we're put parameters between parent eases parameters , but must be separated by a comma. And for each parameter we must precise it's there, a type and its name. We can have any number off parameters we want. We can also choose to you zero parameters. In this case, we just let empty Parentis is here and after it we have the body of the function with open curly brackets and inside. We put the instructions that will be executed when we call the function. Finally, we can have the return statement in functions that return something we must have a return statement were right return than the value that we want to return. I know that a function can return on Lee one value and I said earlier if the return statement is executed, the function and directly and returns that result on the program moves to the code that comes after the function called. We can also use the return statement in avoid function when we want to end it. But we just write return without any value. After it, we'll see all that in examples lasting in this video, we will talk about the position off a function in the program. First thing, you have to know that each C program contains at least one function, which is the main function. The program wouldn't run without it. Second thing. Not that we can't create a function inside the function. So, for example, if we have the main function and we want to create another one, it must be outside last thing. You have two choices one creating a function. You can choose to put it before the main function in the program like this, or, if you want to put it after the main function, you have to declare it before the main by using a prototype. The prototype contains the return type, the function name on the parameters on a semicolon at the end. Don't forget the semicolon. So if we want to put a function after the main will have to put its prototype before the main than we have the main, then we have the full function definition after it. Now let's move to the next video to talk about the best by value and the pass by reference . See you there 39. Pass by value VS pass by reference: Welcome to this video where we will talk about the past by value and passed by reference to important things that you need to understand about parameters. You have to know that when passing a parameter to a function we have two ways to do it. We can pass it by value. It means that the program will create a copy of that parameter in another address location that will be deleted when the function ends. It implies that modifying the Valley off that parameter won't modify the original value we use the past by Valley one. We don't want to modify the original value. Let's see an example. Let's create a simple faction that increments the past parameter. We have void because the function returns nothing. The name and the number as a parameter on inside you, right number plus plus toe increment, the parameter. Now let's call it from the main function. If we print the value off the variable after calling the function and we compile, you can see that it didn't change because we passed the perimeter by value, so it didn't modify the original one on the second way to pass parameters is passed by reference this time we want to create a copy. We will directly past the address off the variable. It implies that if we modify the value off the parameter, the original value will also be modified because they are in the same memory location. And for that the parameter has to be a pointer. Appointer is variable that holds the address off another variable. So we have to add this ass risk. We will talk more about pointers in another chapter on in calling the function, we have to add this 1% before the variable because we want to pass its address. Remember, we did the same thing for scan F. Let's take again the function we made which increments the value off the parameter. The parameter becomes a pointer. Same thing inside. So now if we call it from the main function, bypassing the dress of the variable. If we compile, you can see that the value got modified. It was five and after the fraction called, it became six. So the original value changed. In the next video, we will make a lot of fashions to understand better how to use them. Before ending this video, I want to show you this gift that I've found on meth warehouse that come, that shows the difference between past value and passed by reference, who have here a cup of coffee and the function that fills it at right. It represent the past by value. You can see that the parameter is a copy of the cup. So when it's filled, the original one isn't modified. But that left who have the past by reference, we gave the address of the cup to the function. This is why it got field after calling the function, see you in the next video to create some functions. 40. Let's create some functions !: too much theory. Let's create some functions. Try to create each function we're going to do before watching the solution first function, a function that returns the square off afloat number so the result will be off type float. Let's name it square and in parameters, we only need the number that we're going to square. We won't modify it, so it's passing by value and inside the function, we just directly return the number multiplied by itself, and we get the square. If we call this function in the main to calculate the square off 4.58 on we compile, we get 20.25 64 respectively. Next function, Let's create a function that calculates that some off two integers A and B the function will return an integer Let's go. It's some in parameters. We need to introduce A and B and inside we just returned the some A plus B on. We got our function. If we tried with 10 and five, you can see that while calling the function we respect the number of parameters required here we needed to. So we passed two parameters and be not less and not more, and by the way, we could directly right 10 and five without using variables. When we compile its program, we get 15 third function. Let's make a function that brings the multiplication table off a need to jump from 1 to 10 . It returns nothing. So it's void pipe, Let's name it multiplication table and parameters. We need a nature that we can name, number and inside. First we print that it's a multiplication table. Then we need the four loop or I goes from 1 to 10 and inside, with print number multiplied by, I is equal to number times I. If we call our function with the number eight, for example, we get the multiplication table of eight function number four. Let's make Bullen function that very far. If a character is vowel or not, the function returns true or false, so it returns pulling type to use bowling type. We said that we need to include a city ballpoint H and now function is off. Dybul, let's name it is vowel in parameters. We need the character that we're gonna verify. Let's name it ch. And inside the function will return this bowling expression where we compare the corrector with all the lower case and upper case vowels. And in the main function, we can ask a user for a letter than by using this function. We can tell him it's a volatile or not. Here are examples. Now let's create affection that doubles the number. So what's gonna happen here? We will modify the original value. So what do we have to do? Yes, passed by reference, we must give the address. Let's thought the fraction returns nothing, so it's void here. Then let's name the function double number, for example. In the parameters, we said that we need the address so it will be a pointer on inside. We just multiply the parameters by two like this. And if we call this function from the main, you can see that the variables value got modified. Now let's create the function that swept the value of A and B. So the value of a becomes the value of B and the value of B becomes the value of a. We're gonna change the original values. So we need to pass by reference. The function will return nothing. So we right vote. Let's name it swept on for the parameters we need. The pointers A and B. Now let's see the instructions. As I told you in the beginning of the course, one of the ways to swept to values is to use a temporary variable to store the value off the first number to be able to use it later. And yes, you can declare variables infection. They will be deleted from the memory when the function ends. So let's declare a temporary variable where we will store the actual value off a. Then we assign the value off B two a. Then we assigned the value off the temporary variable to be, and now we swept the value off. I'll be let's verified by calling the function. Let's choose is equal to 10 and B is equal to 20. Now we call the function, and now if we print the values of A and B before and after the function, you can see that we swept them. Next function, we're gonna make a function that returns the maximum between two integers I and B. The function is off type inter job because we will return an integer Let's name the function Max and Parameters we need the two integers A and B. We don't want to modify the value, so we will pass them by value and inside. We use a condition if is bigger than be will return a else where it turned be by this function, I wanted to let you know that we can use multiple return statements in a function, but only one of them will be executed. Not that we could use the Turnberry operator next function. Let's great function that prints all the numbers from one to a given limit. First, it's off devoid. Let's name it's print numbers in parameters. We need the limit, which is an integer on in the function. First, we check if the limit is smaller than one. If it's the case, would directly put the return statement to exit the function. Now. In the case, the limit isn't smaller than one. We use a for loop or I goes from one to limit and inside we just bring the number with a back line after it, and we got our function. Know that you're not obliged to set a return statement and avoid function. Now let's call the function from the main If we choose, for example, 10 as a limit, it will print all integers from 1 to 10. If we choose minus five, it will directly exit because minus five, it's more than one. So we get nothing print. Next function. We will create a function that prints the positive dividers off a positive integer. For that, we need avoid function. Let's name it print dividers in parameters. We need the number on inside. If that number is negative, with directly returned to exit the function. Now if we pass, that condition will print one because one is a divider off every integer. Then we need a full loop that goes from two not one, because we already printed it, the number divided by two. We don't have to go until and because the biggest possible divider off and accept itself is on divided by two. So we stopped there and we set a condition if number month I zero with print I because it means that I is a divider of our number. Then after the loop, we print our number himself because every interview is a divider off itself. But we verify before that the number isn't one because if it's the case, we would print one twice, and we got our function at now. Let's use it in our next function, which is a function that prints the dividers off every number from one to limit, it's avoid function. Let's name it. Print dividers, wrench in parameters. We need the limit inside. Who said the condition that if limit its more than one with darkly exit after it, We need a full loop or I goes from Want to limit on inside each iteration Recall the function we made that prince dividers off a number, so each time it will print the dividers off I on. We put a line breath at the end of each iteration. Let's call this function in the main with 16 as a limit on here is the result. We got the dividers off each number from 1 to 16 so that was our last function. I think you understood the concept of a function. How'd and how does it work, but you have to practice a lot of them because they play an important role in programming. You'll find the source code off all functions we've seen in this description. Let's move to the next video to talk about the built in functions 41. Built-in functions: Welcome to the last video off this chapter, where we will talk about the built in functions. You have to know that there is functions that are available in libraries so you can directly use them without her defining them by including that library in your program, as we did for printers and scanners. I told you that printer friends can't have are two functions that are available in the input output library that we're including in the beginning off every program. But there is a lot of other lib libraries that contain a lot off useful functions. For example, type of age, which contains function that are related to time controlling or math point age, which contains functions that are related to math. We also have libraries made by people that you can find on the Internet. You can also make your own library with all the functions you need. So just to tell you that in programming you should search for a built in function before your task instead of always reinventing the wheel. So that was the last video in this chapter. I hope you understood. Well, don't forget to practice on functions a lot. Great. A lot of functions and try them and see the result. You can always ask me in private message, See you in the next chapter to talk about a race. 42. What is an array ?: new chapter arrays. Okay, let's suppose you want to solve the age of two persons. You'd have to declare two variables named H Person one and H person to, for example. But what if you had 10 persons or 100 persons? Would you declare 100 variables? It's really exhausting and inefficient. This is why you can use a data structure named Ray. What is an array? An array in C language is a data structure where we can store multiple elements off the same time. For example, as we said earlier, we may want to solve the age of 10 persons, So we need an array off 10 elements where the first element represents the age of the first person. The second element is the age of the second person and salon. There's some things you need to know about a race first that an array in C must have elements off the same time. You can't put a native John on the character in the same array. Second thing, you have to know that elements often array, occupy successive addresses in the memory. For example, we have an array off five inter jars. We said that the sides off a variable off in type and a 64 machine is four bites. So if the first element is in the address, 10002nd 1 will be in 10,004 the next one will be in 10,008. Answer. One third thing you have to know is that each element in an array has an index and that we start counting from zero. Remember this? So the first element will have the index zero. The second element will have the index one. The third element will have the index two and so on for other elements. So, for example, if we have in the ray off five elements there, indexes will be 01234 respectively. In the next video, we will learn how to declare an initialized in the ray and how to access to its elements. See you in the next video 43. How to create arrays: Welcome to this video where we will learn how to declare an initial Lies in the ray. First, let's declare in the wreck. The syntax is very simple. First, we have the data type that will be in the array, for example, in Torch Our Any Other data type, then the name of the Array. It follows the same rules as variable naming. Then, just after it between brackets, you put the number of elements off your array. So, for example, if we want to declare an array off five elements of type and we're right and you can choose the name array, so we write array than just after it. We put the number five between brackets because we want tohave exactly five elements in the recent C languages versions. You can put a variable as the site of the array, for example. We could write this, so that was the first method to declare an array with declared an array without initializing its elements. So we didn't set the values that will be in the array, so we have the second way to declare an array. It's by initializing its elements. It's the same thing at the beginning we have data, type the array, name the size, and then we can initialize elements by putting the elements in curly brackets separated by comments. For example, we can declare an array off four integers, and we can put 1234 For example. So we write and than the name are, for example, than the size the number of elements then want to treat four separated by commas inside curly brackets. Not that you're not obliged to, said the size of the array when you initialize its elements. For example, in our last example, we could avoid writing the size. The program would declare an array large enough to hold all the values we initialize here. But don't remove brackets, let them empty. Otherwise you would get an error last thing before moving to examples. You have to know that to access an element in an array, you have to ride the name off the array and just have to read the index of the element you want to access between brackets. Obviously on as I said in the previous video, we start counting from zero, so the index of the first element will be zero. The index of the 2nd 1 would be one and so on. For example, if you want to print the first element off our last array, we would write this. And when we compile, we get one, which is the value of the first element. Let's do an example. Let's take again the first example We've talked out in the first video. We can make an array where we store the ages off, for example, 10 persons. So we right into ages, we're gonna initialize the array, so we're not obliged to set the size. We just ride the brackets. And now let's put the edges randomly. Now, the truth said the values we can't access the one we want. For example, if we want to get the age of the first person, you write ages and zero between brackets. If we want to get the age off the fifth person well, right, ages and four between brackets because you start from zero. So the fifth element will have the index four. In the next video, we will learn how to money polite an array, how to fill it from the user, how to reiterate over it, how to modify its elements. And Millie, all the things I see you there 44. Get information from an array: Welcome to this video where we will see the main manipulations on an array. Let's start with the some Let's great the function named a race, um, off type end because we will return an integer in parameters. We need the array and its size. First, if the ray has no elements were eternal because we have no some at all. Now we need variable that we will name some and initialized on zero. Don't forget to initialize it. Then we need the full loop and inside in each iteration, we will add that element to the some, and at the end we will return our some and now we may the function that returns the product off array elements. Let's name it array prod, for example. We need the array and its size than if the you're A has no elements. We return No, and here we need the variable named product. But we have to initialize it on one because if we initialize it to zero, we will get zero at the end because zero multiplied by any number, give zero and in the full loop will multiply each time product by the element of index I and we can add this condition. If product is equal to zero, we directly return zero. Because if product became zero at the moment, it's useless to continue multiplying because we will get zero anyway. And at the end we return the product. Obviously third function. We will see how to get the minimum often erect, that we need a function off type end. So what's the logic behind finding the minimum will refer. Suppose that the first element is the minimum and then we will check in the remaining elements in order to find a smaller number. That will be the new minimum. So let's begin first. If there is no element Witter no, then we need a variable men that we initialize on the first element of the array, which is array off zero. And now we make a full loop where I starts at one and not zero because we want to check the remaining elements and inside we need the condition. If our off our is smaller than the actual men, it becomes the minimal because each time we search for a smaller number than the actual one , and at the end we returned the minimum we found. Let's do the same thing for the maximum. The maximum is the biggest valley off the array. So we follow the same logic as worth a minimum, and we do some modifications. So we chant the name of the function of the variable. And here we're searching for a bigger number. So we turns the operator and we got our function. Last function we're going to see is a bully and function that very far if a given value exists in there. Ray or not, the bully and data type isn't initial available in C. So, as I told you, we need to include the acid doubleheader to be able to use Bullen. And now let's make the function. The function will return true or force. So it's off Dybul, and in the parameters we need the array, it's size are searched. Value on inside would first treat the case where the array has no elements with darkly return false. And now we need a for loop where we will compare each element of the array with the search value. And if we find annulment that is equal to the search value were diet. Lee returned true on the function will stop because we found it on at the end. If we compared all elements and we didn't find the search value, we just returned false. It means that we didn't find it. Now let's try our functions in a program in the man function. Let's declare an initial lies in the ray. We can, for example, decide to search for the value tree. Now we great variable for each function, Call one for the some one for the product, one for the minimum, one for the maximum. Now let's print the results off these functions, and if we compile, you can see that we got the some the product, the minimum, the maximum and that the value three exists in the arrange. You have to know that these functions aren't the only wants to manipulate an array. You can create any function depending on the situation. You can, for example, count the number of even values in the array or verify that all values are positive. For example, before moving to the next video, check the description or I will put a link to source code of the functions we've seen here . See you in the next video to talk about bi dimensional race, also known as metrics, is 45. CourseManipulateArray: welcome to this video where we will learn how to manipulate an array. In the previous video, we've seen only one way to set a raise elements values by initializing it. But we can also, for example, let the user feel the array. For that, we generally use a full loop on for the size. We can set a specific size, or we can ask the user for that. Let's choose the second way now. First, we will ask the user for how many numbers he wants to put in the array. For that, we use a variable that we can name a race eyes on. We scan, but we have to make sure that user gives a positive size. So use a do I loop that will scan while the size is negative or out off the value range. Now we declare an array with that size, and now we use a for loop to scan each element. So we use the variable I as Nate Aerator, and in each iteration, we scan the value off the ice element. So I start a zero because we can't from zero. And inside we put Scott f array of I so in the first iteration, I will be zero. So we will get the first element than I becomes one and you get second element and so on. Let's try this. Let's true six of the size and now we give the values first. Value second value 3rd 1/4 1 fifth, one and 6th 1 Here we give six values, as we decided to do. Now that we feel the array, we want to make useful things with it. We can do a lot of things, but the main thing to know is that we can it rate over its elements using loop. And in this loop we can print the values. We can modify them. We can count the average. We can get the many imam the maximum. You can do whatever we want with those elements. But first, let's see how to reiterate over the array to reiterate over in array. We use the fall up or I goes from zero to array size minus one on inside the loop array of I represents the element in the array with the index I. Most basic thing we can do is to print all array values. Let's do it as a function to be able to use it again later. The type is void because we won't return anything. We'll just print so in parameters we need the array itself. So we need its address on for that. We need a pointer. We didn't see pointers yet, but the pointer is a variable that holds the address off another variable. So to pass in the ray of integers as a parameter to a function, we can write this. We could do it with any other primitive their type, and we also need its size and inside. If the array has no elements with directly exit, then you create a full loop that goes from zero to size minus one, and we just print the element with I as index, followed by a space to have a nice display. Now that we got the function ready, let's try it. Let's first declare an array off five elements, for example. Now we call the function. If we compiled, you can see that we get the values printed. This one was the first example. We can also modify the values we can decide. For example, toe Adwan, toe all values and print them to see the result. So we create a function named Increments all off devoid, same parameters and inside the keep the same loop, we just reprise print by this instruction array off I plus plus to increment the value. And if we call the function with the previous example on, we compile, you can see that values get modified. We can also decide, for example, to set all elements to zero so you can basically modify each element as you want. In the next video, we will learn how to get the main information from an array. How to get the minimum, the maximum, the some the product on how to verify that for a given value exists in the array. But before that, let me just show you how to get the number of elements often array. We will just divide the sides of the rain bites by the size off the first element in bites . And we got the number of elements. See you in the next video 46. What is a string ?: new chapter strings. So what is a string? A String and C language is basically just an array of characters, so we have bunch of characters on put together in an array. They form us drink. So, for example, to soar the world hello. We need an array of characters where each letter is an element of the array. But the difference between a string and a simple array of characters is that the last character must be the no character, so to take again our last example. The world Hello contains five characters, but we need in array off six characters because the last elemental must always be the null character. And obviously the characters are stored continuously in the memory because it's indirect. Before moving to the next video, I want to tell you something about characters. As you know, we have many data types, and two of them are in and char. You may think that it is only made two star nature and not a character, and char is only made to start a character and not an indigent. But it's false. In reality, a character is represented in the machine with its encoding. Remember the asking code with talk about in the beginning. So int and char both started integer on. When we do this, for example, Charles C. H is equal to lower case A. It will assign the asking coat off lowercase A to C H, which is 97 and we to discharge their type to start characters because it occupies only one bite in the memory and it's large enough to store every ask a character. But we can do this if we want, it will work and then it depends on the former. Specify where we put in print off. If we put percentage see, we will get the value of the variable as a character on If we put percentage de, we will get it as a nature. Here is the result, but a string must be an array of chars So we need to use charge serotype Anyway, In the next video we will see how to declare an initialize is drink. See you there 47. How to create a string: Welcome to this video, where we will see how to declare an initialize. The string, the syntax to declare a string is the same us for a race. We write the data type, which is char than the string name, than the size between brackets just after it. Don't forget to put an extra character in the size for the null character. For example, if your string will contain six characters, you have to put seven outsize and we can initialize it. We said that a string is in array of characters with a noble character at the end, so we can do it by ranting each character on the no character at the end. But it's too long. This is why we can directly put the whole text between double quotes like this without even typing the null character and Samos arrays. If you initialize the string, you can avoid setting the size so you can write this. Now that you got your string initialized and you want to print it, you have to use percentage as as a former specify like this on you can get this. We will learn how to scan a string properly later on In the next video, we will see the streak point h other a very important header to manipulate strings. See you there. 48. string.h functions: Welcome to this video where we will see the different functions off String point H Heather to manipulate strings. But first, let's see how to manipulate a string without using a function. We said that the string is basically an array of characters, so we will use the same method as we did with a raise. We will use a for loop to reiterate over all the elements until we find the no character. And inside we can use the Element Off Index I, for example, who can print all the characters. Or we can set all the characters to lower case A. For example. Now let's see the street point age functions. Don't forget to include it in your program. Let's start with STL Land. This one takes one parameter, which is obviously the string, and it returns its length without counting the no character. So, for example, s tail and hello returns five. We also have a CR cat, this one a pence's drink at the end off another one. It's like we're doing this, but this is not valid Insee. So we use a CR cat. We need two parameters. The destination string and the source string For example, if we have a Sierra one is inside on a sir. Two is code and we call the function with a stare one as the destination str one will become inside code because we added the second string at the end of the 1st 1 The 2nd 1 doesn't change, by the way, we also have a Syrian cat that looks like the president one. But the difference is that we have 1/3 parameter, which is the number of characters we want to add at the end of the destination string. So it will comply the first and characters of the source string if we call it with our last example and which is to as the number of characters will get this because it compared on Lee the 1st 2 characters which are sie and oh so str one became inside coat. We also have a C occupy this one literally capaz the second string into the 1st 1 We need it because it wouldn't work by doing this. So the function takes two parameters the destination string and the source string on by calling it, it will comply the second parameter string into the 1st 1 we can try it with our last example on the output will be code. We also have a Sierra occupy. This one looks like the president one, but we need 1/3 parameter, which is the number of complied characters on. It will comply the first and characters from the source stream to the destination string, but it doesn't remove the remaining ones. So if we do this this year and one becomes co died because we replaced three first characters off the Destination string, which is a Seirawan by the three first characters off the source string, which is, as they are to we also have a Surkamp. This one is useful to compare two strings. It takes the two strings as parameters, and it returns zero if they are the same one. If the first train comes after the 2nd 1 in the dictionary, minus one. If the second string comes after the 1st 1 in the dictionary, so to verify that two strings are the same as your compass return, zero had not one be careful. We also have a CIA rev. This one will just take a string as a parameter and will reverse it here is an example. We also have a sir upper and lower. The 1st 1 will uppercase all the letters of the string passed us parameter. And the 2nd 1 will lower case all its letters. Here is an example for each one. We have other functions in string point age. You can check the Lincoln description, but the wants we've seen are probably the ones that you will use the most so focused on them and see you in the next video to see how to scan a string properly. 49. Scan a string properly: Welcome to this video where we will see an alternative to scan off. Ah, more secure way to get a string as input. We have two men problems while using scan have to get a string as input. First, it stops at the first black character. So if we scan inside code, we will only get inside at not the whole input second problem, which is more dangerous by using a basic scan. African control the size off input given by the user. So if the user gives an input that is bigger than the string size capacity, it will cause a buffer overflow and it's very dangerous. This is why you have to fix the limit size off the buffer. To avoid this and to avoid these two problems who have an alternative to scan it, which is have gets f gets, take three parameters the destination, the buffer size and the file. So here we will put the string where we want to start the input. Then we put the maximum number of characters that we want to read, so we will generally put the size off our string on for the follow you want to read from keyboard. So we put STD in always put a city end. So, for example, if you want to read the string named user name and its size is done, you write this and you can see in the example below that even if the input exceeds the size , it will stop a 10 and we can also read the string that has spaces. But the last problem is that at the end of the string, we will generally find the line break character, and we want to remove it. So we check the last character in the string. And if we find that it's the line break character, we replace it by the moral character. We can haven't create our own function. To do these two actions. It will be avoid function in parameters. We need the string and its sides than inside. We will use F gets with the string size as the buffer size. Then we tell the last element on. If it's the line break character, we replace it by the moral character. Here is an example off this function called, and by this way we finished our chapter about strengths. See you in the next chapter 50. What is a pointer?: welcome to this new chapter where we will talk about pointers. Very important chapter that will show you the potential off C language because it is one of its most interesting properties. This chapter can be quite difficult to understand at the beginning, but by following well, you can become very comfortable with it. So get ready. So what is a pointer? A pointer is just a variable that holds the address off another variable. If you remember, I said in the beginning of the course that each variable has an address in the memory and the pointer is a variable where we can stole the address off another variable, and by using it, we can access to the value of the pointed variable. We can ever modify it if you want. Now let's move to the next video to learn how to declare an initialize appointed 51. How to create a pointer: Welcome to this video where we will learn how to declare and initialize a pointer lets darkly start with the syntax. First, you have to know that the pointer has a date. A time on this one follows the data type of the pointed variable. So if our pointer points to a variable of type end, its data type will also be off type end. So we said that we have the data type first. Then we put an asterisk. This asterisk is an operator that we've seen. Sometimes during this course by this operator, we can differentiate between Appointer and the simple variable. And after it we need the pointer name on it follows the same rules as for a simple variable on the semicolon. Obviously at the end, let's do a simple example. For example, we want a pointer to a variable of type end. So we're right and that the s a risk then the name, for example, P than the semi call. We have these two other ways to put the asterisk because we can also put it at the beginning of the name or join everything together. Now we have an end point er so it can hold the address off a variable of type end. But how can we do it? For example, Let's declaring invariable named Numb, for example, and initialized to five. And now we declared in Pointer for it. We can't initialize it like this because we will get the Valley off number, but we want it's address, not its value. And to get its address, we need to put the M percent operator the address operator before the point of variable, same as we did many times in this course in cold by reference. For example, we gave the address as a parameter, if you remember, because the 1% is a urinary operator that returns, it's operates address. This is why we use it. So we put an end percent than the pointed variable. So by doing it in this example now are Pointer P holds the address off our variable number on If we print the value stored in our pointer, this is what we get it just the address off, numb in memory. But it doesn't mean that we will always get this value unnecessarily, because we can't predict where the variable number will be stored so it won't be sort of the same place every time. Let's do a second example. Let's declare a variable off type char initialized to lower case A. For example. Now, if we want to point to this variable, we can create a pointer of type char than the S a risk than the pointer name. And now we can initialize it to the address off ch. So now our Pointer p two is pointing to ch. Imagine a pointer as in a row to a certain memory location on By using it, we can't access to the value of the pointed variable on we can ever to modify it. If we want, we'll learn how to do it in the next video. See you there. 52. CourseDereferencePointer: Welcome to this video, where we will learn how to the referenced a pointer in all the world's how to access to the value off the pointed variable. Let's take the example of the last video. We have the variable num of type end and initialized to five. Then who created a pointer p that we initialize to the address off number. So now P holds the address off, numb right? So if you print the value stored by our pointer and the address off numb, they will be the same. But we want to get the value off the pointed variable, not the address on. For that. We have to put an asterisk like this, also called the D reference pointer. So if we print as to risk B, we get five, which is the value stored in the store address in the Pointer. We can even get the address off the pointer itself because I said earlier, the pointer has also in addressing the memory by using the ampersand before it the dress operator and you can notice that it's a different from the address off numb because they're two separate variables in the memory. Ensure the pointer without any operator returns the address off the pointed variable numb in this case and the pointer with the stairs before it. The difference Operator returns the value off the pointed variable and the pointer with the M percent before it, the address operator returns the address off the pointer itself. To better understand, let's suppose we have our variable numb with five as value and start at the address 1000 in the memory. So at the address 1000 we find the value five, as you can see, and we have our Pointer P that points to numb and stored at the address. 2000 in the memory. So at the address, 2000 will find the Valley 1000 which is the address of the pointed variable numb. And now take some seconds to find the valley returned by each one off this three elements post the video and try to guess Let's start the value returned by the pointer without any operator is the address toward in it, which is 1000 the Valley returned by the pointer with the deference operator before it is the value off the pointed variable, which is five. The value returned by the pointer with the address operator before it is the address off the pointer itself, which is 2000. Take some seconds toe. Analyze this because you really have to understand it before moving to another thing. Now that we've seen that the reference operator, you can see that we can access to the pointed variable and its value through our pointer. It's what we call the referencing a pointer on a sad earlier, we can avenue modify it for that. We just ride the pointer name with the difference operator before it and we can assign a new value to it. For example. Here we said, the value tend to numb through our pointer on. If we print numb before and after the instruction, you can see that it's value change Foreal. But what happens if we change the value stored in the pointer? The actual value stored in the pointer is the address off numb. But you have to know that we can change it. For example, when we want to point to another variable, For example, we have another invariable named Numb, with 15 as value and sort in the address. 1000 and five hundreds. At the beginning we initialized our pointer to the dress off numb, which is 1000. But now we can assign the address off, numb to tow our pointer if you want. So the value stored in it will be 1000 and five hundreds because now it points to numb to. And if, with the reference it we get the value of the actual pointed variable, which is 15. Let's analyze this, go to understand better. We have our two variables num and num to initialized to five and 15 respectively. And we have our Pointer p initialized to the address off numb. So now it points to numb. So if you print the value of numb, we get five pulls the video to take some seconds to understand. If you want you understood this must let's continue now with the reference the pointer to change the value off numb and we set it to 10. So if we do referenced our pointer, we get the new value off numb. Let's continue now. We child the value off our pointer itself and we set it to the address off. Numb to So now it points to numb to and if we the reference it, it returns the value off numb to which is 15 As you can see now, increment the value off numb to buy the referencing the pointer and using the increment operator. The parent eases are important here. And if we print the Valley off numb to now, we get 16. As you can see, here is a little animation to understand, because is the most important video off the chapter. Here is a little animation to see what happened in each instruction. Watch the video again. If you didn't understand, because it's the most important video off the chapter now. Do you remember that in the chapter about functions in the past? By reference, we passed the address of the variable on the parameters was pointers at not simple variables. It means that there is a relation between pointers and functions. Let's see it in the next video. See you there 53. Pointers and functions: welcome to this video where we will talk about the relation between pointers and functions . You have to know that a variable declared in function can to be used in another function. It's what we call a local variable. And don't forget that the main is also function. So if we declare a variable numb, for example, in Maine and we try to use it in another function, we will get an error and vice versa. So to be able to use a variable in another function, we talked about parameters and we have passing very value and passing by reference, impressing by value. We don't really give access to the variable directly. It will create a cup I in the memory that holds the same value and will be deleted at the end of the function. This is why the original value can't be modified, so to be able to access to the original variable, we used to call by reference on how did we do it. Instead of passing the variable itself, we passed it address on as parameter. We use the pointer that will hold that past address and now that the pointer is holding the dress off the variable declared in the main function. We can reference it to access to the point of variable, and now we can access to its value on we can ever to modify it if we want. You really have to understand this concept because it's very important in Brian and passed by reference. We passed the address as a pointer to be able to do Ferentz it and access to the variable even if it's in another function. Let's see, for example, of function, that ad stand toe a number. Here is what happens with cold by value. We have the function and we call it from the main and we passed the value. So what's gonna happen here? The function parameter and will be created in another memory location and will hold the value past as parameter, which is the value off our variable numb. So you can see that instructions will be performed on the created parameter and and not lamb. No, the instruction is to add stand to the function parameter, so on will change on will be increased by time. As you can see, it became 15 but you can see that non didn't chant and at the end of the function and will be deleted from memory at Nam States now will be deleted and the end off the main function . So we didn't meet our goal, which was to increase number 10. This is why we're gonna use passed by reference. What's gonna happen first? Here is the function. The parameter now is a pointer. And why did we use a pointer? It's because while calling the function, we will pass the address off numb and not its value. So we need the pointer to store the past address. Now that we call the function, the pointer will be created in another memory location and will hold the past address, which is the address off numb. So it will point to know. And inside the function we will the referenced this new pointer to be able to access to the variable so we can increase the value off number 10 by writing this so you can see I tried that the value of Nam changed. And at the end of the function, the pointer will be deleted from the memory. I hope you understood the relation between pointers and functions. What's the video again if you didn't understand. Now let's move to the next video to see the relation between pointers and arrays. See you there. 54. Pointers and arrays: Welcome to this video, where we will see the relation between pointers and arrays. Let's quickly check the definition of a ray again, and the ray is an index data structure used to store a collection off elements of the same data type. But what interested is the most is how is their stored in the memory. For example, if we declare this a write off five investors, we suppose that it's a 64 bit machine, so and occupies four bytes. What's gonna happen if we suppose, for example, that the first element will be stored at the address 1000. The second element will be stored at the address 1000 and four because an end occupies four bytes and the third element will be stored at the address. 1000 and eight in the fourth element at 1000 or 12 and the 5th 1 at 1000 and 16. But what is the relation with pointers? You have to know that our without brackets after it can act like a pointer, and it stores the address off the first element. Let's see what we get if we print the value of our and the address off the first element. They are the same. So interesting thing we can do is to the reference, are toe access to the first element here Is it we printed the first element by the referencing are you can ever modify it if we want, and we can do the same thing with the remaining elements. If you want to access to the second element which has the index one you, the reference are plus one. Don't forget the parent eases in general toe access to the element with index I we can do it by the referencing air, plus I. And if you remember in functions we were passing a race like this. We don't put the m percent before our because I said earlier it's already and address the address off the first element. This is why the function parameter is a pointer. It receives the address of the first element than we can directly access toe all elements. We can also said the array parameter like this, by the way. And we can also do the same process for strengths because the string is also in the ray. Don't forget, but the string contains elements off type char which occupy one bite in the memory and not for like end. So if we declare this drink and the address off, the first character is 1000 the string will be stored like this and we can do the same manipulations using a pointer. And we can use pointers to point to an array. Same thing for strength. So this is the end of our video. In the next one, we will see an interesting thing we can do with pointers, which is Maria location. See you there. 55. Memory allocation: Welcome to this video where we will talk about memory location if you remember in a race chapter we created in array to hold the edges off 10 percents. But what if suddenly we needed more elements because new persons arrived or at the opposite some persons left? So we have any use elements that are occupying space uselessly. We can't fix it using the type of array we used because it's a static array, it means that was declared, We can't change its size. So if we declared it with 10 elements as its size, it's impossible to change it later so we can't add or remove elements. This is why, in this video we're gonna learn how to locate mammary dynamically. The main advantage of dynamic arrays is that we can change its size during execution as many times as we want, and to be able to do that, we will use what we call memory allocation. And to do so, we will use four Estela functions Malek Kalac, rail lock and free. Before diving into them, we have to know how much size an array occupies. If we have an array off 10 elements off type end on. Each element occupies four bytes because it's off type end and 10 multiplied by four is 40 so there a occupies 40 bites. So in general, the size often array is the number of elements multiplied by the size of each element. The Pentagon. It's their type. Now let's see the first function, which is Mulk. This function takes one parameter, which is the size we want to allocate in memory and returns a void pointer that points to that are located. Marry location. A void pointer is a pointer that isn't related to any data type. So we can use Malek with any pointer type and without casting. What did we say about a race size in memory? We said that it's the number of elements multiplied by the size of the data time, and this is exactly what we get. A pass as parameter and Malek, the number of elements stored in the variable and, for example, multiplied by the size of the data type, and the result is assigned to our pointer. So, for example, if we want to create an array off five floats right float pointer than the rain aim, for example, float array and we initialize it to mark five. Multiplied by the size off flow data type, the size of float is generally four bites. So here we are located 20 bytes for our array. Second function is Kalac. It looks like the previous one. This one takes two parameters the number of elements and the size off one element. So we don't do multiplication here because they are two separate parameters. And the main difference with Malik is that colic initialize is all the elements to zero. Before moving to really work, you have to know that when we allocate memory, it's possible that their location fails when there isn't enough space, for example. So after ah, locating, we have to check if they'll location is don't successfully or not, so we set the condition. If the result is no, it means that it didn't located successfully, so we can print it and we exit the program. We use Exit zero for Windows as the allocated is don't successfully, so we can perform our instructions. Now we're going to see the function that makes it possible to modify the size off our location during the execution. It's really lock function. This function takes two parameters the located area and the new socks. We will see its utility in an example in few seconds. Just the time to talk about the last function which is free this one. Will they allocate the space previously allocated by Molla Kaleka Rail Look, it takes one parameter, which is the allocated area and it will they allocate from memory. So the pointer will have the value? No, after it on, it's better to free every allocated space before ending the program. As we will see in this example, we will take the example of person's age. But this time I will use memory location at not just a simple, static array. We will first create in the ray off 10 ages because we have 10%. Then during the gala, Christian new persons will come so we will increase the size of our rate than some persons will leave. So we will reduce the size of our array. At the end, we free the allocated space. Let's talked in libraries, we need Onley, STD, io and STD lip and we can define 10 as the initial number of persons before going to the main function we can just create a function that will print all the ages like this now in Maine would declare the variables We have the number off new persons that will join the number of persons who will leave and the actual number of persons which is initialized to the initial number of persons which is done. Then we declare their rail using Malek. So we have an end point er that receives the result off Malik The number of persons multiplied by the size off into their type and if they are location felled with exit darkly after it will fill the array by the edge off each person we use the do I a loop very far that the impetus positive now would print the ages afterward, new persons will join. So we ask the user for the number off new persons. We make sure that we have a positive value. Now we add the new persons to the number of persons. So, for example, if there is three new persons, we will have 13 persons in total. And now comes the interesting part. We will increase the size for that. We said that we use real look the first parameter is our ah located space, which is ages on the second parameter is the new size, which is the number of persons multiplied by size off end and we assigned the result Toe ages. Note that the old elements values won't be removed, so we don't have to feel it again. We just feel the added elements. Then we check if relocation is made successful or not after it would get ages off. The added persons for that was scanned the initial numbers persons plus I, because we want discount the element at the end extent at the index relevant and so on, not from the beginning. And we obviously make sure that the edges positive using a do I loop after it will print the ages again to see that the array chance, after we to ask for how many people left will make sure that it's a positive number on that it doesn't exceed the actual number of persons. Then we subtracted from the actual number of persons and we're a lock again. If the reallocation fell to exit, then we print the ages again to see that the array changed again and at the end will free the allocated memory than the program ends. And here is an output example. I hope you understood this four memory allocation functions and see you in the next video. 56. Key points about pointers: before ending this chapter. Let's just see some key points about pointers. First, we said that the pointer is a variable that hold the address off another variable. Second thing is that the pointer. If we don't initialize it, it will generally be initialized at No, this is what we call a null pointer. It points to nothing. Third thing the Pointer data type generally follows the pointed variable data time key Number four. We can the reference a pointer to access to the pointed variable. But to be careful, never the referenced no pointer. Always check that your point. Or is it no key? Number five Avoid Pointer can point to any data type, but we have to use casting one with the reference it. Key. Number six. We can have a double pointer, a pointer that holds the address off another pointer. For that, we use double asterisk. For example, we can have a variable lahm start at the address. 1000. A simple porter start at the address 2000 and pointing to numb and a double pointer. Start at the Address 3000 and pointing to the first point. Now we can have access to numb with three ways by using non directly by the referencing p one owns on by the referencing P two. Twice with two Asterix like this and you can see that we get the value off mom in the three methods, Key number seven understanding pointers will make you comfortable with functions, arrays and strengths. This is why you can watch this chapter again if you didn't understand, because it's the end of this chapter now, so see you in the next videos. 57. Conclusion: So is the end of our course. Congratulations. You made it to the end. I hope that you're now comfortable with programming fundamentals. I hope that you learn new things from this course. Keep practicing. Keep building projects to become a better programmer everyday. If you ever noticed something wrong in the course or that you wanted to be added, you can send me a private message. The icons used in the scores come from flat icons dot com. It has a lot of beer for icons on the author's Off. The icons are used here are free pick, pixel, perfect smash Aikens, Flood icons, Vectors, Market Diner, Soft Labs and suing. They have really nice Aikens on for the gifts. I found them on Giffey that camp. So don't forget to put your harness review about the course and to share the course to other people of possible. You can also visit the Instagram page of Inside Coat, where you can find a lot of useful things related to programming in general. So I hope to see you in another course. Why not? Maybe the wants I'll really created you can have a look on them and good luck with your programming journey