C Programming: Master C Language and Programming Fundamentals | Lukas Vyhnalek | Skillshare

C Programming: Master C Language and Programming Fundamentals

Lukas Vyhnalek, Microsoft Employee, Programming Teacher

C Programming: Master C Language and Programming Fundamentals

Lukas Vyhnalek, Microsoft Employee, Programming Teacher

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

    • 2. What is programming

    • 3. C HelloWorld

    • 4. What is Variable

    • 5. Data Types

    • 6. C Variables

    • 7. Logical Operators 1

    • 8. Logical Operators 2

    • 9. If condition

    • 10. C if Condition

    • 11. Switch

    • 12. C Switch

    • 13. Arrays

    • 14. C Arrays

    • 15. What is loop

    • 16. C For

    • 17. C While

    • 18. C doWhile

    • 19. What is function

    • 20. C functions

    • 21. When to use functions

    • 22. Pointers

    • 23. C Pointer

    • 24. Struct

    • 25. C Structs

    • 26. C How to get input from user

    • 27. C Calculator

    • 28. C SumOfArray

    • 29. C Biggest number from 2 Arrays

    • 30. C Get Random Number

    • 31. C Guess Number

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Save your precious time by taking this course, This course is designed to show you C language, and to help you understand programming fundamentals. This course is designed for complete beginners, so there is no need for previous experience with programming.

This course is great if you want to start with programming or if you want to learn/improve your C programming skills.

In my opinion, long lectures are boring, so in this course, I try to explain things in a fast and engaging way so I won't bore you to death. Also, there is plenty of exercises on which you can practice. And if you get stuck or if you need anything I will be there to help you, mostly I respond to questions within a day.

In this course you will learn:

What is programming?

Variables, data types

Conditions, if, switch

Arrays, loops


Pointers, reference


Also in the course is plenty of simple application on which I explain important concepts.

Meet Your Teacher

Teacher Profile Image

Lukas Vyhnalek

Microsoft Employee, Programming Teacher


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.



1. Introduction: programming is the future. If you know programming, you can get great job with the lots of benefits. These days, firms are desperate to find programmers, so they are able to offer you plenty of benefits. By the way, why is that? If learning programming have so many benefits, why aren't there more people learning it? Well, it is not easy. Lots of people give up, but you can definitely learn programming like everything. It is all about practice. This girl's will teach you the basics like what is variable? How to use if condition, What is array loop function? Also in this curse are plenty of applications on which you can practice. So do you want to learn programming? 2. What is programming: Waters Program program is a set of instructions, so programming is basically telling computer what to do. But you can communicate only by instructions that computer can perform. It's same way. As with humans, you have instructions. So if someone tells you to shut up, you know what to do. Or if someone tells you to raise your right hand, you can do that. But if someone tells you to drive a car to Mars, you cannot perform that operation. Computer worries the same way only the instructions looks like this store. Something in memory at 10 and 15 is 15 bigger and zero thing the top left pixel to read. Now you might think, OK, that's great. Bad. How do we create a useful application with these limited instructions? Well, you bragged the application to set of instructions. Think of it this way. If you get lost and ask for route, you will receive a set off instructions like go one mile, turn left, then take the second right and you can miss it. But if someone tells you yeah, it's two miles dead way you will get lost. Same way with computer. You cannot tell computer. Hey, dude, is that? No, you have to tell him. Bring this on a screen. Take that from user, multiply this and debt and print the result. So the important thing from this lesson is that you are telling computer what to do. Set bicep using instructions that computer can't perform. 3. C HelloWorld: Hello, Gas. In this lecture, I will show you how you can create your first The application? No, I am using a program called Visual Studio. This is, I think, 2017 edition. You can download it. It's for free, just right. Visual Studio 2017 and you should be able to get it. It's Ah Microsoft, I guess, is making these. But anyway, if we want to create new application right, we go file, then hit new and brought Jacque. Then we can choose from what kind of applications we want to do. So make sure to click this visual studio C C plus plus and here we choose what type off applications we want and we want council application for starters. Here we choose our name, though let's say my first project and you can also choose the location of your project. I will just leave it the same and hit. OK, then visual studio is going to do all the heavy lifting and create all the 1000 need to be able for you to write gold and create applications right? So year. As you can see, you have our source files. And since I created c++ project, and this curse is on C. I will change this CPP to see Okay. And do you also have to change it here? So this will make sure, Dad, this application will be in C Don't. Now here is the main function. This function is called when we start our program. No, since in this lecture, we won't just create be one. Just create an application that prints simple Hello, world on screen. We gonna use this brain function, right? This is a really cool thing. It kinds Ah, kind of tells you what you might be looking for. And that's great, right? This Sprink f Then in parentheses, we write what we want to print, and we wrote it as a string. So we right. Hello, world. Now. Well, this will do. This will bring hello world on screen. And that's all we need to do to do this, right? And also on every line we need to write on end stem accord Under rice, we would get like this error, right? You can see these red Underline, and it said if you hover over this, it says expected a semi corn, right? So you need to put Sema coin otherwise you won't be able to run your app. And now we are. We have all we need to run this app. No, If you go to D Back and click this start without debugging also you can do control plus f five. He were short gap. I used his monks less so yes, but this will run our program right? And it might take a while for this to kind of compile to get together. But eventually you will see this and it says hello world. Right? And this is some like system. It's the message those So you can close this window by making some keyword about anyway I wanted now to and d line under after hello word. So what I will do is right back slash and end This backslash is behind a telling computer A I want to do something that is not just bring thing I want to do some something else, right? And this end those computer a nd line Also we can have like he that's just tap. So if I run this right now, you should see Hello. Then there will be space than world. And then there will be end of line. And that's exactly what happened. Right? So, yes, that's pretty much it for this lecture. I will see you later on. And the applications we will do later will be more interesting. Bad. Anyway, do you next time? 4. What is Variable: So what is variable variable is basically a space in memory where you can store something and you can access it by name. And why is it called variable? Well, you can change its value. How many times you want. The variable will still live somewhere in memory, and you can still excess it by its name. Only thing that changes is its value. Variables are in every program and in every application that you use, so it is important to know how to use them. So, to sum things up, variables gives you the power to store data in computer memory and easily excess it or change the data by name, and you can choose the name. It's only up to you. Other important thing is that D variable have something called data type. This thing defines what values can be stored in this variable, for example, numbers or characters, and I will talk more about it in the next lecture 5. Data Types: the type of variable is defined when you create new variable. Mostly, you want to start something basic, like number or character or string, so you can tell the computer A. I want a memory for some number, and I want to excess it by this name. It is actually much simply, or Dennett sounds that Why do we have to define type of variable to computer? Everything is just zeros and ones, so he doesn't care. Rotary store number or character? Yes, computer doesn't care. This feature is added for US programmers because if you write some complex application, you need hundreds of variables and there is no type. After a while, you will get lost and do something like multiply a string by number instead of multiplying two numbers and your application would crash. So we need data taps that not because of computer. In the beginning, the thing that variable can be set on Lee to one data type. It's kind of a pain in the yes, but as you get more advanced, you will appreciate this feature the most years. Data types are indeed er and killed you right in, and it can counting numbers from minds to billions in something to to billions. But this number can't have debts. Um, appoint similar data type is short, which can contain numbers without decimal point, but smaller. It is from about minus 30,002 plus 30,000 that mostly you will you've seen dangerous instead of short. I just want you to know that something like this exists. If you want to soar really big numbers, you can use long data type. This allows you to store numbers that have 18 zeros, and that's a lot. If you need store decimal numbers, you can use double date attacked. Here, you can store numbers like 10.8 or minus three. Another data tap you will definitely use is character and killed the right car and can contain one character like a or dot or space. And another data type is string. It can contain, for example, hello world or James or any other string. Another data type. It's important, mostly in conditions. It is bullying, and it can be set to true or false, and that's it. If you have any questions, just ask, and I will see you next time 6. C Variables: Well, hello, guys. In this lecture, I will show you variables. I believe you already watched the kind of explanation video where you learned that variable is something that lives in memory and we can access it by name. So now let me show you how we can create very ever in our program. Percival were you write our data type. So, like this end. Then there is this name off our variables. So for example, my number and then I can either and the lied. And if I do this, this will only declare variable. And what do I mean by that? Well, this variable, my number will already live in memory, but it won't have any value. Okay, So if I want to set some value to this variable, I just write my number equals sound value 500. So and now I can do all Fencik kind of Start with this, though, for example, I can bring this number and I will use that by writing my number. And now I need something that tells computer that I want to print this variable right, because this is just string computer looks at this and he see only strength, so he didn't know he cannot match this with this. Okay, So you we will tell computer that we want to print variable using this percentile side. And then we say, what type of variable we want to print. And it is indeed er you Right? Hi. Then we write Sema Corn. And here we passed the variable like this. My number. Okay, Now we cannot forget to put semicolon at the end off the slide. So now what computer will do is he will bring my number as in text, and then he will go and see this. And this is a way I need to bring some variable. And then he looks what is here. And he see this is vary ever. So he goes to memory Big Five under and puts it here. Okay, so now if I run this well, actually, let me also put his here End of light, okay? And if I run this program, it looks like this. So my number variable is 500. Okay. And here I can show you that if I change IHS variable to let's say, for example, 20 and then I bring this again. I will just kill P pays this because I'm lazy. And here it will say 20 because the value have changed that the name heaven. Right? So let me show you and write. It says 20. So now we can do also underthings with these variables. So let's say I want another number though my other number and I will already initialize it to 50. Right? So this is where I declare. And here I also initialized this variable to some value. So now I can say my other number. It's equal to my number. And what these line does well, it takes my number. It takes the value from my number and it says this value through my other number. Variable though this variable will be 20. Brad. So if I go ahead and horrendous so you believe me, you will be my other number. Here will be also my other number. If I run this, you should see 20 and you do okay. And now let me show you another useful thing. This is this has nothing to do with variables. But you will use it definitely. And it is a comment where if we sometimes want to like put some note to align. So we know what this lined us, right? And we will do that by this two sides. And now I can ride like this line brains. My number. Okay. And computer will not evaluate this. He he knows that this is only for me. He has nothing to do with this, so he won't do anything with this. But if I forget on these signs and right, just this something something blah, blah, blah. We will get this red underlined that indicates ever. Okay. Also, if we want to write comment on more line, we can do it like this. So if I ride here, multiply its it's all commended and computer won't go through all of these. Okay, So let's get back to our very it most if I do some operations which I can do but say in my third there, third number iss. And now I can initialize it to, let's say, buy times my number. Though this is also possible. Computer takes five and multiplies it by value stored in my number. And that is 20 right? So you can also bring it so you will believe me. I will just right number because I'm too lazy and here will be third. And if I bring Dad, we will see 100. And that's five times 20 is 100. So that's OK now we can do all of these fancy Stop, Bob. I want to show you another data. Types like our this data type will store one character. So I will just ride my car. And in here you write this quotes and inside we write the letter. So it's a for example. It can be any letter you want. And now I can just print it, right? But I will not cap it. This stag I right brained. But you know you can choose. And now all right. My care is equal. Do. And here and we are not printing numbers anymore. I will write, see as a car because this variable is our daily tie though Now if I write semi corn and as here this variable right, I will I will see my car is equal. Do a So let me run this program. And as you can see, my car is equal to a and I forget to put here the end of line. No. Now I want to show you that these characters are actually still numbers. And this might sound weird for you that if I right here, let's say I know her. My other car will be equal to my car. Plus one. You might You might think this is nonsense. You can't at 12 character, right? What? What will it look like? It would be a one or something like that, Actually, no. All of these characters are from something called Ask your table. Right. Though a is represented as like some neighbor. Some number, I think 48 I guess. I guess I'm not sure. But if I add one to it, it will be be so. If I bring this character again right here, I will write my other Ferriter and you will be also my other character. It should be be. And I run this program. You may after way the vile that eventually you will see that it is actually be right. That's kind of weird, but it that's how it works. Okay, so now let me show you what all of the kind of operations you can do, right? You already saw multiplication. That's one You can also divide. And you can also add and do modeler operation. So here, if by right let's say my number that is this variable I declared here actually, let me get rid off all of these things so they won't bother us. And if I said it to my other number under number that IHS actually 20 right? Because here we changed it So I can divide it by Let's say five and this will store for into this variable, right? And if I bring Did I say okay? My number. And if I print it, you should see for and you will that's for so right. If you do minus there will be by 20 minus five. That's 15 You do plus terribly 25. And if you don't Modelo there will be zero at and Modelo is this percentile side and what it does This This is actually the rest after dividing with five right, though if I actually is that my other number two Let's say 22 this will be to day. So if I run this, you should see to and you do Okay now let me show you While we can also do Okay. Okay, I know. So, no, this Waas let me get rid of this and said this to zero. And now I can change this number using something called Increments. And it just says less bus, my number and what else? Well, it adds one to the value of my number, So this will be wanna okay, I will. I can also do do it like this My sorry, my number Last bus. And the only difference between this and this is that the incremental is happening here under this land right here about here. The incremental is happening before, like, you probably don't know the difference. And it pretty much doesn't matter at this point. But if I run this program, you should see one. And if I run it, you actually do right here is a welder. And also I can do ECR amending. And that will look like my number minus minus. And that just takes one like it do minus one. It do actually. This my number equals my number minus one. This might sound weird, but we can said my number two the result that uses my number one variable, right? What computer does when he gets to this line is he says okay, my number. So he takes the space in memory and then he impute what to put their but he computing. He can compute it because he haven't changed this yet. So he picks the value that is start in my number says do this operation and that stores the result into my number. Okay, so that's exactly what is happening when Deacon menting these lines do the same. And if I run this, you should see zero because here it is 01 and then euro and in a zero. So now actually, let me show you some double. No, If I write here double that I can write So double my where variable and I can store Let's say two born five for example. And now I can do all fancy Stop so I can just say my there will be equal. Actually no, no. We'll be equal to my wear plus my number So we can also add to variable of time double we can add variable off type end that we declared here And actually let me get rid of this though the my number variable will be one. Okay, so my var variable will be free 0.5 And I changed it here my var And here I have to change the I to act. And if I run this, you will see 3.5. Are you good? Right? And you can also do this actually with another double, right? So my var to will be equal to, let's say five born three And if by Addis my of our two, you should get like 7.8 by sound, right? And I think I do because it is seven point day. And now let me actually show you some bullion variable. So in order to use Boolean variable, we need to include the STD Bull Library And okay, let me explain what this include. Does somebody else wrote some code and he stored it into this vow. And if you want to use the coat somebody else world you use, this includes keyword and this kind ah grabs all the code that someone else's world and puts it in inside here. Right? You can see it about It's like it is here. So now I am able Thanks to this, used the bull data time So if I right here boom. Cool as a bullion, right? And some name and I store their route though you can see it. ISS like corporal something. And in this variable, I have room. I can also store their force day. And now I can't bring this variable. Right? So only in variable X it is. And here I write the and I passed the variable here. And since this prince numbers course zero and true is one I actually will write it. Like here there is one and force is zero. It kind of makes sense, right? Computer is all made up from one and zero and one is true. Zero is false, right? And if I print this, there should be zero. Yeah, it's false. So it iss by and okay, this Boolean variables are heavily used. There are really, really used in in conditions and in loops and I will talk more about it later on. Uh, feel free to play with this. See, what do you can do? What kind of operations you can do with variables. And if you have any questions, just contact me. I will try to help you and I will soon except by 7. Logical Operators 1: you probably know smaller than operator. If something is smaller than something else, it is true. Otherwise falls. These kind of operators are heavily used in every application. The expression could look like this brewery invariable is set to the result off, then is smaller than free. As you probably figure out, this variable will have value of force. Also, you can use the expression like if some variable is greater than zero. If values starting this variable is greater than zero, it is true. Otherwise falls. Other operators like this are the bigger than or bigger than or equal to or smaller than or equal to. Other useful operator is these equal operator, since we are using equal sand for assignment, if we want to check weathered value is equal. Rewrite two equal sides like this, so then it's equal to 12 will result into force, and 10 is equal to 10 will result into true. Once again, you can use variables as an operates, so instead of 10 you can have some variable instead of 12. You can have out a very ever and check whether they are containing same value. Other heavily used operator is not equal operator, which is defined as exclamation mark and equal sign like this. So 10 is not equal to 12 is true, and 10 is not equal to 10 is false. And once again you can use variables instead of a prince. I suggest you play with there's a bit and I will see you at the next video. 8. Logical Operators 2: logical expression returns bullion value, so the result is either true or false. It takes some operations and these up Arends have to be also bullion value. So true or false, first thing we can do is negation, which is these exclamation mark and what it does well, it flips the value so negation of true is false and negation of false is true. I open and makes sense. Other logical operator is sent. This operator returns true. If both arguments are true under rise in returns false. So for example, bull result equals two true and false. We basically store false to result variable. Another useful logical operator is or there's operator returns false. If both arguments are false, otherwise it returns true. So for example, true or false will result into true. These operators are extremely helpful in conditions. As you will see later on, you can combined these into more complex expressions like true or false and true that I recommend doing this when you get more advanced at the beginning just great new boolean variable and set it to the result of false and true and then do true or are variable With that being said, you can play with this bit and Duyvil See you next time 9. If condition: if condition is essential Without it, we would not be able to decide and make smart application. So it looks like this. We got the if key vert, then we have parentheses, and inside them is condition behind this. Parentheses are braces. Where are the instructions we want to execute? And these instructions are executed only if the condition is true. If it is false computer counting use by instruction under braces. As a condition, you can have some born in value, so falls are true or boolean variable. Also, you can write their expression that results into bullion value. So, for example, then is less than 20 or for example, 10 is less than 20 and 20 is bigger than Ferdi. This condition would result into false, so instruction embraces will not be executed. Also, you can use else if it looks the same as regular. If Onley this side only this time it have to be placed right under if or another else If conditions and the code embraces is executed on Lee when every condition bath was not mad. The last instruction this else this instruction have no condition. It has only braces. It has to be placed under some if or else if condition at and executes decode when all the if and else if conditions above. We're not mad. I think you will understand it better on an example. So let me show you. 10. C if Condition: Well, hello. In this lecture I will talk about conditions. So I got here some project named Conditions and I also include STD Bull. So I am able to use bull variables little values and don't forget to write here. See instead of C plus plus there see PP No. Now if I right some if condition right As I said in the explanation video year in Bren, theses will be some condition, some expression and the year we write our coat, our instructions that we want to execute. So if then IHS Mahler than 50 let's say I want the Brent I want to bring Let's say 10 is smaller then a 50 or starts And don't forget on Sema Coid, right? So if then ISS mallard and 50 If this is true, this line will happen. Otherwise we will continue and do nothing. OK, so if I around this program a minute to compile this well friend then is smaller than 50 day about If I guy in the changes do 10 is bigger than 50. This will become force and this will not be executed. So if I run this again, you will see nothing because this Will wasn't executed. Yeah, though. Now, let me show you another thing we can do here. We can write else if this else if must be under some if or some else it. Right? So I right here. Five. This Moller Dan, then, right? Don't forget on these braces you can The spring here by IHS Smaller Dentyne. And what computer will do if he sees goes like gold like this. Well, he goes and see this f though he tries to execute this. If this is true, he do and execute this. And then he jumps out and goes, like on the end, like here. Okay, But if this is false, he jumps over something that is inside his braces and he jumps and goes, Do this else if condition, right? Okay. No, actually, this will be force. So he will go ahead and execute this and he see that five is smaller than 10 though he will print this. Okay, so if I run this, we should see five a smaller Dan 10 and we do by the smaller than 10. No. Now, if I change this right, though, this is not true. And this is so so true. But since this is L stiff right, I want to demonstrate the difference between else if and normal. If here's the If And since this is true, this will take place and then we jump out. So this will not be printed in. Even though this is true, this will not be printed. If I run this, you shall see it is actually then a smaller than 50. And this wasn't executed? No. And if I now change this if this this jumps only here, right? And this is the next time. So computer will execute this. So these both sentences will be printed. Okay, Now let me show you what else does when we write else. We do not write any parentheses because this will take place if all the conditions above we're not mad. So if I change this right five small, bigger than 10 that is false. This else condition will take place. So I bring here like else I bring just else. And you shall see that years else. Okay, so now I want to demonstrate that I can also do you like something like this though else if then iss smaller than 15. My friend Tennis smaller than 50. Okay. And this well code this whole block is one condition. Right? And this is false though this one will be executed. And since this one will be executed, this one will be jumped over. So we will see. Then it's smaller than 15 right? So now I want to show you. Since comparing 10 and 15 is pretty much useless I want to show you how we can do. Yeah, I understand with variables. So if I define here actually, let me get rid of all this stuff. If I define here new variable gold, my var and I said it to 20. And here I defined other variable though Those smaller number and I said it to say minus 10 . Okay, so now I can compare these for example, my war IHS bigger than smaller number. Oh, sorry. It's father number. And this is true. So here I can do all kinds of stuff there. I don't have to bring anything. I just skin but they set my bar. Ah result of my war. Times two. I'm super, for example. I can do anything, anything in here and there can be multiple lines like five r is equal to I r minus five or anything right, though. And if I run this and actually let me bring my of our here though I bring my bar, uh, and and of line. And here I passed my var Sorry, my are Oh, damn it. I like this like this, though. Ah, this my bar will be. And this is true. These lines will take place. Okay, so it will be 20 times two. That's 40 minus five. That's ready. Five. So if I run this program, it should bring My bar is 25 35 And it does so great. No, If I kind of changed this condition, these two lines will not take place. And you can see it by looking at my bar. It will be 20. It will not change. So now actually, let me show you some Them more complex. Let's say conditions I put here car Let's say my carrick, sir. Right care and I will set it to X for example. And I can now check whether my car IHS equal. We used to double equal sign do Let's say a okay, I can do that. I can compare characters like this though actually I can also change this and right here. And And my var is smaller then smaller number. This will be force though actually this is a bit more complicated, Complicated condition And actually let me bring my var if this condition is met. So my my character is X so this will be false. Okay, this will be force. And this they'll be also false though this will not take place Balls and force it's false. And if I change this like my var is bigger than smaller number that is true. I still get both because this will be true. Okay, But this will be force so balls and four false and true sorry will result into force. But if I change this to or and or is just these two sides, this will be This will be true. This whole condition will be true. This will take place. And if I run this program, you shall see that it took place. Well, actually that's all there is to it. If you have any questions, just ask and I will see you in exam 11. Switch: a switch statement allows a variable to be tested for equality against the list of values each values go. The case and the variable being switched on is checked. For each switch case, you can have any number of case statements within a switch. Each case is fold by the value to be compared to and the Cullen the constant expression for case must be the same data type as the variable in the switch. And it must be a constant Wendy variable. Being switched on is equal to a case. The statements following that case will execute until a break statement is reached. When a break statement was reached, we jumped out off the switch and continue with another statement. And other important thing is that not every case needs to contain a break. If no break appears, we continue with next gays. A switch statement can have a non optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. Also did the fourth case IHS same as else statement in the if condition and that's pretty much it. So I will see you at the next video 12. C Switch: Well, hello, guys. And this lecture, I will talk about Rich. So if I declare something teacher variable, it's a number. And I said it to 20. Then I can switch over this variable. And here I write my cases. Okay. And your Iittle computer, I want to switch over this variable. Very simple. Don't. If I write here case and let's say by and in case number is five, I want to grinned. Let's say it is by Yeah, And then I cannot forget to on this break statement, though. I just got b this and write some more cases, though, In case it is Sten, I'll bring It is then story up brained it iss him. And now, in case it ISS when he a print that it is sweaty right in this case will actually take place. It is 20. And now I can also right here, big fault. And I can read here. Just default, Walt. And this will take place if none off these cases above were not met. So if I run this, you should see it is 20. And you can OK, but if I change this, do the 220 this will be printed So as you can see default. Let's see what will happen if I forget on some break statement. So if this will be 10 and I forget on break under the stent Stone computer evaluates this like he tells. Okay Number. That s 10. So he compares its then Samos five. No, he jumps over these two lines. Then he goes here and compare istan Samos Stan it iss though he does this line and then since we do not break out he continues with these And then he reached this break statements . So it will be also it This 20 will be also printed. If I run this, you shall see And it is It is then it is 20. Okay, so it is important to you. Kinda not Forget on these break statement and okay, let me show you another example. No, if I let's say a character room user and this will define some operation then we want to do for example plus Okay, I can switch over care variable. There's nothing wrong with that. So if I do this switch and here I write operation that is this variable and your eye right braces inside them while the operations can be. So in case. Right, I have to write these growth. And in case it iss minus minus, I will do, actually let me be. Find some numbers so and number do and number free. That is actually how you can declare numbers. Okay, you can declare more numbers, exit more variables of the same type on one line. And you will do that by separating them with this comma. And you can also initialize them on one line like this. So this want to stand? This one is 20 and there's nothing wrong with that. Okay, though, in case it is minus, I will do number two. All right. Number two is equal to number two, minus number free. And then I break okay. And I can just copy paste that for every operation. Like so these will be plus also noticed that if you write to named cases right, the studio is smart enough to tell you that you already wrote this case online to any free . That's great, right? Though you can just do this like I do. How amazing. And here I divide. So I also write some default case. Sorry. The fault case where I print let's say unknown operation for example, unknown operation like this. So if I run this actually I also need to bring the value that I have in my number in number two variable Though Aikins is right, the result is then Ah, do it like this. You already saw it like 10 times. So I will not commend what I do right now. Though this should bring the result is and then bus 20 right, so 30. And if I run this, you shall see some error. Okay? This is actually what happens if you do something wrong. And the studio is also good enough to tells you where the error is. I can already see the error and it is right here. I forget on f about anyway, if you can see right? Actually, this is pretty bad then. Really bad message, right? You cannot going to tell anything from this, but mostly it is. It is more reasonable. It tells you Hey, you have error online. 38. Excellent. With me, Judas away. And it would be better, I guess. Yes. It tells you a online 39 right here. Oh, yeah, it's fine under, but it tells you syntax, error, missing semicolon before return. Right? So that is great. And anyway, if I run this, we shall see the result is 30. And we do So now we can just change these operations minus. And it will still work, though. Yeah, actually, now, let me re variety this rich into if this should be interesting. So I will commend this. Okay. Also, another cool feature is that you can collapse this. Okay, if you wanted to disappear, but still be there bread. But anyway, if I check whether operation he's equal do minus minus. And here I do just the same by a number. All right. Number two is equal to number. Do minus number free. Right? And there there is else if and you already know what to do, right there will be else. If operation is equal to Plus I will do. Plus and so on and so on until e. L state man, where I write like this there Waas, I'm sure right now. That friend it unknown operation. Oh, right. And yeah. Still, dad is how you can rewrites rich into if and mostly for this kind of work where you compare with on variable with X cases with encases, you want you switch? Actually, it's gonna better. I guess it looks better. And But if you do pretty much any other operation you you should use it right? Anyway, if I run this, I will get the same result. It should be my understand. All right. And this man Anistan. Great. If you have any questions, just ask in. I will soon extend. 13. Arrays: array is basically collection off variables off the same type in one. Let's say we want to store my salary from past them months we could have. Let's save 10 variables off type end, and in each of them have one month salary. But better way to Saudi values of my salary from past them. Months is a ray Ray is declared like this, so we have the type than name. But right after name R squared brackets inside this brackets, we right size of our ray or number of elements if you want. So in our case, Dan, And if we want initialized this collection with numbers, we write braces and separate individual month salaries with Gamma Brenda. Good right. But the best thing is that we can get to each month by its index. But the weird thing is that we start indexing from zero. So these are indexes of each month. And when we want to access a month in array, we just write the name of our ray and then squared brackets and inside we right index off the month we want to excess. And if we want to change value at some index, we ride ones again, Name squared brackets and index equals to some new value. So it is same as with variables and one last thing when we will. New Ray, the size that we are defining in square brackets must be constant expression or constant variable, and the size ovary stays the same throughout whole program. When we want to dynamically increase the you're a size, we use something called Malik Function. But I will talk about it in following lectures, and that's pretty much it. If you have any questions, just ask, and I will soon except 14. C Arrays: Well, hello and welcome to this lecture. In this lecture, I will talk about a race. So, as I said in the explanation video array is collection off some data, right? You can think of it as a group of variables. So if I want to declare a new array, let's say I want the elements off this array to be off type int. So I right here in my are and I can actually there goes this square brackets and inside them I defined the length off my IRA, though, for example four okay. And I can just end And what this line does is it tells computer A I want space in memory or four in teachers and I want to excess this space in memory by my are variable by my our name. Okay, so actually, let me initialize it. So if I want to initialize some array, I can do that by writing braces by writing braces and inside them I write my elements. So for example, one do free floor. Okay, though this will initialize my array. And now if I show you print using print f function Dad, my array on index zero IHS and here I write percent. I I and I end the life. So now I will pass. Do this, do this brain function. I will pass there my are like my array and then embrace it in squared brackets. I will access the element by index. So zero will be the first first element. Ok, one will me. This one do will be this one and three will be this one and them according to end his life . And if I run this program, you should see my array on in that zero is one right. And it also may take a while to compile. Okay. And here it is. My are on in the zero is one the great That is how you can excess thes elements on the race . And what I can also do is defined them variable And I can set this variable to my are on index one for example. But the type of this variable must be the same type off. You're right, right. Though now I will have in There's variable. I will have this number. And if I print is like variable just variable iss and you're I passed the both and If I run this, you should see Variable is too. And it is pretty cool, right? And I can also do so sad. Like I can set this variable 25 and this will not effect this. Okay, so I said the variable 25 But this will stay the same. This will be still too. Okay, so who demonstrate? I will print it. I will bring my array on index one. Okay. And it should be too. Even though I changed the value of variable and it kind of makes sense, right? It is too, because the variable if somewhere else in memory. Okay. And now I can also said the element off my array using one's again this using this index, I can set it to variable, for example. No, instead of four will be five. And if I print it like this right under, I will. Yet by Yeah, now let me show you that you can also, instead of constant number right here, we can use variable so and I will be too I as an index, this is used in cycles. That's going to spoiler alert. Sorry. Bad. Now I can just ride my array on index. I is equal to 10. That's nothing wrong with that. And what a computer does it, he goes, OK, here's my array. And here's the index, but in once number. But since it is variable, that's okay. He just goes to memory picks to and, you know, access these third, the third number in this ray because we are indexing from zero, though instead, off greeny will be Ted. And now, if I bring it like this, I can also use here you I Yeah, who is variable And actually let me show you another feature. So this brained F dysfunction can also bring multiple variables in one sentence. Okay, so if I write in my array on index, I where I want to set this is variable, right? I want this variable instead of this. And then I want this instead of this. Okay, so if I just right here Hi, This should work because computer evaluates this like he goes. Okay, Okay. Okay. Okay. And here goes percent a lie. Okay, so I need some number. So he looks here and see OK, here's number. So he grabs it and put it here, grab the value from the address off I that is to and puts it here. And then he goes again. Okay. Okay, okay. Nothing. Nothing. And here's another number. Though He grabs this one and puts it here, though it should say my right on index to is then. And if I run this, you shall see Yes. Wait a minute for it to compile. Uh, it shouldn't take too long. And your it iss my ray on index to ISS, then read. Now I want to show you another thing or any. Sorry, Ray is basically off any data types so I can write our my array and here and be empty braces. And it says incomplete type is not allowed. Right? So I need to I need to set it to some value like this. And now I f empty space in here. But I can also initialize it like this. And here I can write the characters. You know that I can use string value and string is defined by this quote, and inside them are just right. Actually, some eighth character like ABC the 1234 okay, and, 093 uh and no, this is character Okay, so this will be on in that zero. Is this another character? And you may notice there is 12 free for 567 off these that we can in order to work with strings. We also need to have something to determine the end off our strength. And in C and C plus bus, we use this two sides and computer automatically adds these who a strength when we define string like this. Okay, so here's automatically added these two characters, right? No. Now, if I want to access it, I can print it like this where I write just now. Percentile this on index percentile. I, for example I can use still this I variable And now I can write just my are became my heart array My car array on index I will be on index do that means see And then I bring the I. So let me show you how dad looks. It should be sti is on index to and it iss right see is on index to so you can also change these character same way as he in the year right that we can also bring strings so bring death and by adhere Percentile s is a string night Jazzier. My, our ray. Like this whole array and I around this brings the hall array as a string okay to a B C D E f g I forget to put the end of line here, but yeah, that's it. You know, you can use this to define strengths because and C we cannot just right string because it's not a date a time, you know, You see this red underlying intent off identifier string is identified, so yeah, we have to define strength like this. And that is eggs. Exactly what strength? ISS. If you think about it, String is a beret off characters, right? And that's pretty much it. If you have any questions, just ask in. I will soon exam. 15. What is loop : As the name suggests, Loop repeats the same set of instructions over and over until receiving the order to stop, and the order to stop is mostly defined by some condition. So we look while this condition is true and when it is false, we move on to instructions under the loop. Also, we can get out of loot by writing break statement inside this cycle. Remember how we used break in switch? This is pretty much the same. And do remember a race Loops are off the news. If we want to go through some collection of data like array, we got free types of cycles for a while and do while for cycle is used when we know how many times we want to loot. So, for example, if I know that I have 10 names in the ray, I will use four cycle while cycle loops while some condition is true. So while cycle is used, when you are waiting for something and you don't know when it will happen, so four is used when he know how many times you want to look while is used when he don't know how many times you want to lose. I will show you examples in next lecture. The last cycle is do a while. This one is pretty much the same as while about this time, instructions in loop are executed at least once. I know this might sound confusing, So let me show you some examples and hopefully that clear things up. 16. C For: Oh, guess in the lecture I will talk about four cycle or four loop won't. So when we want to write some for Luke, we write for then in parentheses. We right? Some indeed. Your value. We usually use I as an index. Right? And we can declaring like this. So indeed your I is equal to zero. Then they're Sem accord. Then you right are ending condition. Let's say I is smaller than 10 and then we have something that is happening at the end off each cycle. That is this gold finally expression. But you can call it whatever you want, right? And it is happening right here. Okay. At the end, after all the instructions right here. So no, all of these free lines are optional. You can, for example, they find this right here. Okay, That's the fire and leave this empty. It's okay. It still works. But let me just put it back for now. I will talk more about it later on, though Now, for I from zero while I smaller than 10 I will increment I and do this. So for starters, let me just bring brains. I is equal. Do and here will be the value if I Yeah, like this and cynical. And if I compile it, it should be eyes equal to zero all the way up to eyes equal to nine and it iss right from zero. We go all the way up tonight, though this now in a cycles while I smaller than 10. And it all Whoa for for. And then when I is Sten, it jumps out. There's will not be execute. Okay, though. Yeah, that's pretty much it. Now let me show you what we can do. For example, with a race, let me define, um, race called numbers. Where will be 10 numbers? Yeah, and this is Ray will contain. Let's say 10 15 20 01 You our actually let me do a little bit less numbers by 1234567 Numbers. Yeah, seven numbers. I filled it with pretty much around in numbers. And now all I need to do to change this ISS do numbers on index side. So then spy started zero, and we are indexing from zero. We'll grab this number, then we move up increment I as a final expression, right? That is happening in here? Yeah, And I will be one, though this will be printed. Then this will be printed, and this will be printed all the way up to the end. And we have to change this your seven. Because if it would be 10 we would reach behind your A and we would get error. So if I run this, I mean, just right here. Number on Index, I I is equal to nothing. And you should see that it printed all the numbers from this ray right and story. I can just right here on indexed. I like this will be better on Index. I like this. And so I ran it. This is better number on in. The zero is Stan and we go all the way up to six, right? Those by this on index six. And then when we increment, I will be seven. And it will be no more smaller than seven. It will be equal. So we break out of this four cycle. I hope that makes sense. And I think it does. Now let me show you how we can river ride this cycle, though that there is none off de Isla. None of these expressions. Okay, I do not recommend doing this, but we can do that just for educational purposes. Okay, so four and they're here. Should be declaration. You should be ending condition. And here should be final expression. But I can do it just like this. And here I defined in, is equal to zero. This is this step. Okay, then I need this ending condition and I will do that by writing here. If I is smaller than seven now, you might think, OK, then. When I smaller than seven, this will take place about the instructions under this brand will still be evaluated. Right, though we will get ever Well, actually no. If were you right here, break what this lined us is when actually no, here must be neg. Negation on it. So when? Like this, though, when I is not smaller than seven, right. We break out of this four cycle and that is exactly what was happening here when I waas not smaller than seven. Right When I was seven, we break out though seven is not smaller than seven. Exactly this condition, so yeah, and last thing we need to add is this final expression that we did here and that's in this four cycle does the same as this one. I do not recommend doing this. As I said before God, it's going to get to know if you want. And if I run this you see it is the same. Same result no good. I will delete it because I don't want you right. It's like this, but you can. Another thing I want to show you is that you can ride more four cycles inside inside, other for cycle. So where I will change Jeanne Variable. This will be the scanned counter inside off this four cycle. And while G is smaller, Dan five I will increment G. Yeah. So now I can kind of bring, for example, waiting for G two by. And this thing, this thing will be Brent it. Exactly. Exactly five times I will end here the end line and y five times. Well, it is zero, and it is incremental each time we end. So and go swan. Well, for zero, it's print it. We're one in this. Printed for two, it is printed for free. It is printed and before it's printed, good as five and this will he happening? Each time we bring our number, though, when we print our number, we then bring five times waiting for G to be five. And then we go in this cycle back to this cycle, increments I and go straight up. OK, so if I run this, you should see this, right? I may have chose a bit smaller number than five, but never mind. You know, it is exactly what I said it would be. Wait five times waiting for G to be five. And yeah, Since we are declaring this variable all over again this four cycle, we'll always be five times execute. But if I, for example, with this statement here I can do that as I saw previously. Bad this side. This variable will be five in the first cycle. But then when it comes to second cycle, G will be already be five and will not be zero. So we break out. So when this time this time will he printed this only five times. Only when we are printing first number, then it will be kind of skipped over. So if I run this, you shall see and right you shall see. Is it exactly? I hope you understand it. This is a bit more advanced, like cycles inside cycles. It maybe takes a bit more going to imagination, I think. God, I think you should get it. It may take some while to kind of get used to it, but you should get it. If you have any questions, just ask, and I will soon exam. 17. C While: low gas And this lecture I will talk about while cycle. So let's get started if I to find some in teacher very a book and I called his variable counter. I said it to 10 and then I define some while cycle and I will cycle while counter is greater radar equal to zero. Okay. And then I right braces and inside them I write instruction that will be executed while counter is greater or equal to zero. So I can, for example, brained the counter though I read counter iss and then I write percent I I So I just pass here counter Abdullah, this should bring counter is then nine something something. So then if I d Kram encounter here the comment that means counter will be counter will be equal to counter minus one. These two lines does the same. Then computer jumps right over here and execute this condition again and it will do this cycle. It will cycle. He will loop while counter greater or equal to zero. So if by around this program you should see counter in Stan nine and all the way up to zero and it is, But I forget to end the lions by adhere and run it again. It should look a bit better. And Indust, though. Yeah, that is what while cycle doubts. And if if you already saw the four or lecture you should, it should not surprise you, right? It's kind of like the four cycle when we declared variable in front of this cycle and then we have the final expression right here. So while is basically or loop bad, let's say that I want to define Bull very ever. Next, let's say I will set it to true the true. And here I real ride while x So this will cycle Oh, all over all over until this ax is false. And if I never changed this X, for example, if I just write the year and x ISS, then I bring decks. I will cycle and then compute the real step right So you can see it Cycles, cycles, cycles, cycles and it will never break out because this will still be true. Okay, No, really. Right now I need to yourself because it would stack or forever. Almost. But anyway, I need to change this. Eggs values somewhere at some point though. For example, if I right here if then it's smaller den when he that ex do false This kind of doesn't make sense. Right? But just for purpose off each in. Okay, it is useful though world will happen. We will jump in this wild cycle and then then is smaller than 20. So this will be false but this will still be executed. The condition will be force when we go up. Right? So there will be printed X is zero because we changed X to force. And when we print force, it is zero. Now let me show you what will happen if I that X to force some of you might know about this will be boss though he called inside, this braces will not be executed. And if you look what in the console there is nothing. Okay, good. So now that's pretty much it. I think I did not forget about anything actually. Let me show you that you can do cycle inside another cycle. For example Why? I don't know. I iss smaller den Danner. Yeah, and here I will sit. I encounter don't do girl. And here will be also counter that is the cool thing about visual studio. If you write something like this, they were all medically tells you that it is under undefined though you are American. No, to look and see that you meant something else. Okay about anyway, if I bring here counter Yeah, I like this about any other text I will just bring here counter area boy, it will does the same. And here I said it and I can set X to force in here, for example. So now I want you to think about what will happen. This is true. So we will jump inside his braces counter will be set to zero. And while counter is smaller than 10 we will go here brained rent the counter. And then we said x two falls. And right now, you might think you might notice that we would cycle here forever. Right? Because the counter variable will still be zero about If I incremental did, we will break out eventually. After 10 it rations, we will break out and brand X is zero because it will be force. And that's it, right. This will be false. So we will break out off this cycle And if I run this, you shall see you go from East. Brains are like brained I counter. Okay, that's all these lines, right? From 0 to 10 and then this spring will happen. Okay, We also can do this break statement. So this will bring. Actually, we This is important. If we use this break statement inside some inner cycle, we would break out of this inner cycle, not out of this outer cycle. So it will. There will be printed counter. Zero eggs will be set to force, and then we break out. So this will be also printed that this will be false. So if I run this, you should see a zero and then x zero. And do you do okay, that's pretty much it. If you have any questions, just ask in. I will soon examine 18. C doWhile: no gas And this lecture I will talk about do while cycle So this cycle looks similar to while cycle that meanwhile and the condition is at the end off this cycle So like this and this bigger than in well and the year must be also semi card, right? So do this block of instructions while something and inside here we just can rain something like like Ah, I don't know. I am in a who for example, No Also let me actually define some bull Variable x and now you will set it true. And I will also define some in teacher variable and I will set it to 10 though now if I is let's say equal to five. I will set x both here I will be comment I the I and I will cycle while X So what will happen? X is true So we go in this cycle If France I am in loop then we check whether e I is equal to five. If it is, we set x two false and we eventually break out right Because when we will check this X and will be false. But if it is not we do nothing. Iran Eventually the income de Crimen Sorry, we d comment I So there will be five times five times will be I am in lieu printed I forgot on the you and line here. And if I run it again But you can see 12 free for five, six times Yeah, six times story because we are decry Menting after there's okay, so we are deck amending After this condition, though I will be five in here about x will be still because I waas six in here, I hope I hope you understand it's it's maybe hard for imagination a bit, But if I with this in here, there should be only five times right and it is five times 12 or five bad. Anyway, The thing I want to show you is that I can set x two falls and no matter what access, this will be executed. So even though excess falls I am in, lewd will be printed And then we will break out of this cycle because excess falls God, that's the That's the thing. Here's I am in Lieu printed There's the thing and while cycle we we can break out right? If actually I I will write it if I have here while cycle while X This well bean will never happen because excess force. But in here, even though x is false, this will be executed. Otherwise, you while is same as while you know there's nothing nothing about it, and that's pretty much it. If you have any questions, just ask and I will soon excited. 19. What is function: What is function function is a group off instructions that takes some input and returns output. Yeah, you probably look something like this. If I take the example from Rail World, imagine that you want a coffee from Automat, so you take money, pass it to out a mat, and it gives you coffee or something similar to coffee. In this example, your money is the input, the operations that out, Madison our instructions in function, and the coffee is southward. Similarly with computer. If you have function that accepts us input, some anti jer and the past value this set as value to, let's say, variable X in the body. We do some operation. Let's say X Time X and we were turned. This as you result or as our output if you want, I will explain more how this works. In next lectures, you may notice that this function returns X squared. You can find out it's similar to Mathematica function. If you have Mathematica function, let's say F where why is equal to X squared? Why is exactly what our computer function returns and X is exactly? Would our computer function takes? If you have questions, just ask them and I will see you next time 20. C functions: Well, hello, Gas. In this lecture I will talk about function. So let's get started when we want to declare a function. We right first the returning data type. So let's say we want in teacher. And then there is the name of function. Okay, Like this. So it looks pretty much the same as variable. But then there are parentheses and inside them we define something called para meters and bear me. There is basically what you pass into function though in the previous example it was money , right? We passed money and we get coffee. Okay, so here we will pass to numbers into A and and B and then we have braces and inside them there's something called body off the function and it is just instructions. So tens dysfunction is called multiply. I want to multiply a and B and return the result. So I declare integer variable result And I said this variable a times B and now I can just I want to return the result. So I ride return result though this variable is basically the coffee that we get from ultimate. Right? So now let me show you how we can call this function. First, let's declare variable called them and initialize it zero. And now I can set. Tim, do the result off multiply, for example Free and five. Okay, so I passed free. This will be a and I passed five. And this will be be, though. Now I have in temp Christine. Right, though if I reigned in temp ISS now for since i i and end the line And then I passed them, it should say, And in temp is now 15. And another thing we can do is we can pass variables instead off just constant numbers. Right? So when I declare some, like, end Mm, my number, my number and I said it. Oh, it meant okay. Compilation is done. So it says in temp is now 15. Okay, that's correct. But let's get back. If I set my number 2 20 and I can pass here instead of five, my number and it just if I run it again, it says 50 60. Sorry. And that's exactly free. Times 20. Okay, so devalue that is stored in this variable. It's past, and it it's kinda set to be okay. The great Now let me show you that we can go dysfunction multiple times. So if I declare like them to variable And I can also call it like this when I'm initially initializing the variable though if that has there like five and by for example, them to should be Renate 25. So and them do this Gentile I and I pass here also tempt to value okay like this. And if I run this it says them them is now 60. That's correct. And then two is now 25. So we can call this function multiple times, as you can see and the result is still the same. Okay, right. Let's see another, Another kind of use case off or function, for example. We don't want to return any value and we can do that. Some function doesn't return value. Sometimes we don't want that. So it is just a void that says that this function is not returning anything. Okay, though if I say white, say hello and I also can also function doesn't have to have para meters. Okay, this could be empty and I'll show you how we're this girl's in a minute, But let's say this function brains Hello. Like this. Okay. So I can now call dysfunction in here and it will look just like this without any para meters. Right? Because there are any para meters and it will just friend. Although that's it, it will not return any value. Okay, so it says hello. Pretty good. Right, though. Now, let me show you another use case. Let's say that we want a function that returns maximum value from two past numbers. So end, Max. And here I defined a and B and these will be just the numbers I pass. And now what I can do is like year do this result thing, right? This is gold. Some think Oh, I forgot about it. This is local variable. Though this variable kind of lives on Lee inside these braces. If I right here result for example, under the skull result, I can, for example, started to 50. I cannot do that because this it doesn't live in this inside this main function. Okay? It lives only inside here. Joke. I can do this deal kinda where our store into results a or B whether which one is bigger. But I can also do something like this. I checked better a ISS bigger than be. If a is bigger than be, I'm returning a right so I can just do this return a Okay, so I don't have to declare any local variable. I can just use the value that use a past and I can return dead. And also I can write else because if a is not bigger than be, I want to return Be right. And here I read Be so I do not to use any kind of local variables And that isjust better, right? I can also change dysfunction, though actually, let me amend this. I can change this into return a times B and that works the same. Okay, it just we just lost this kind. Ah, middle step if you want. But Edwards the same though. Now, if I call this, let me actually do it like this brained f where I print Max value off. Let's say 10 and by and I'll use the function. The returning type I won't started into variable. I will just probably like this Max off then. And five, though this actually works. We don't have to store this inside variable. We can just past the result into some other function. So if I run this, you shall see that it says Max off then. And 50 10 or five. It's then right, though it actually works. And I get here end of line so that these are kind of functions. Let me show you another another thing. And that shows you how howdy value is. Start inside here. Okay. So if I right function increment and it accepts some a and it is void so it this it will not return anything. Okay. And what I will do here this I will increment a And today yeah, I hear. Though I will define a and I'll set it to 50. And then I recall increment both a And then I will bring let's say, a ISS now It's now a so like this and you can guess what will be a will it be 51 because we pass here 50 and he re increment though it might be 51 but won't be 51 because we passed on Lee Value. Right? So you can think of that as if the right here and this a This increment will not have effect on this variable. Okay, though, if I run this, it should say a is now 50. And it does. Right? So a is now 50 and we can kinda change the value off this A inside here, But we need pointers for death. So I will talk about that later on and let me actually show you another example. And that will be our last example. And that is a recursive function. So this function will return. Indeed, your value. And it will be called factorial. I'm not sure if you're familiar with bacterial function. And what did the US is basically it, except except some number and And let's say that Ennis four. So the result of factory ISS four times free times, two times one. Okay, Right here. If Annise four, the result will be four times, three times, two times one. All right, so we can kind of use Lou for that, right? We can do that, but I want to show you that you can call function inside function and actually, let me just write the code we end if if n is equal to one, we return. And but otherwise we return and times bacterial off n minus one. So now you might look, but what the fuck Abad? It actually works. So imagine. Did you pass four? Okay, though Computer evaluated. This s he goes here for IHS not equal to one. So he goes into this else branch and he returned for times something. And you don't know what this something iss So he kinda has to go compute this and then he can return to your whole result. Okay, so it caused this factory of it free. Then it cause it with two and then he causing with one. And when one when n is equal to one, we return just one and then it kind of multiplies it back. So actually, let me show you How is it called the brain death? And I'll say bacterial Oh for IHS And then all heavy or some in danger value This and I nd lied. So now I passy or factorial result of Bacterial four though if I run it, it should be four times three times to And that's training for I guess. Yeah. This 24 factory or forest 24. So now you might wonder what is happening in here, and I have a tool that can show you sculpt debugging. Where you if you click on here, you add something called Break Born. And what dead means is it kinds of stab the ever stop the evaluation off dysfunction at this born and it's kinda shows you how D variables look like, though if you click on this local Windows D bugger and this might take a vial, but eventually it will run, and this tool is extremely useful. It is extremely useful if you if you find out your program is not doing something, and you need to kind of you kind of get lost in your coat, that happens, and so you can d bag it and, well, look, something like this if you run it, though, here it says. And that is this variable. It's four. And here we had this cool, well, kind of arrows, I guess where we can step into function, we can step over this call or we can step out. So let's say then we want to step into what is happening in here. Okay? No, As you can see, we jump up and N is now free. So if I just step over it, embarrass and and one and jumps bag here but and it's now free. So if I that over again, it is to write because n minus one, do you? And again now this will be one. It is one and we start to returning the values, though, and is now one. So we return it and that this is the end. So now we know that this factory all returned one and and is now to the we return to. And now we get kind of back to the cost. Really? Previous girls rights where and was free. And we needed to compute bacteria off too. And the factory a love to just return us returned us value. And it was for two. Sorry, though, if I just do this again again, I will get 24. And that is great thing. So if you're uncertain what is happening in your code, you should use this d back to and that's pretty much it for this lecture. If you have any questions, just ask and I will soon exam 21. When to use functions: why use functions? The first reason is reusability. Once the function is defined, it can be used over and over and over again. You can involve the same function many times in your program, which saves you a lot of work. Also, let's say that Do you have a repeating code and you need to change something If you use functions, you changed it only ones that if you are not, you have to change in multiple times. So each time you are writing code that you already wrote somewhere else, you should use function and just go. The function whenever you need, instead of copy, pays these same coat over and over again. The second reason is abstraction. In order to use a particular function you need no these following things. You need to know the name or function. You also need to know what these function does, and you also need to know what arguments you must give to the function. Lastly, you have to know what kind of result the function returns, but notice if you just want to use the function in your program, you don't have to know how it works inside. It's sort of like driving the car. You don't need to understand every detail about the engine and wheels and stuff all you want to do. It's drive the car, so I hope you understand. Functions are great. I recommend using them a lot and I will see you next time. 22. Pointers: Let's talk about pointers. Imagine that memory looks like this. It looks like a table where we match address with data on this address. So in this example, we have address on first grow and data on second row. Now, do you remember when I talked about variables? I said they lift somewhere in memory. Well, they do and imagine that if you create variable, let's say, in a equals minus 50 it is stored in memory. And this a corresponds with some address in our example address 01 Then if we declare another variable off that indeed your pointer pointer in code means this star, then we write name and then there is not value. But then comes reference to some other very ever and killed. We read reference as end side, and it might look something like this. And Star B is equal to the reference off a and how it looks in memory. Well, imagine that variable be lives in zero to then the value of 02 will be 01 because that's where a lifts. So if we ask for reference off some address, we write and sign and then we get the address where does variable lives? And then we can point to this address. Another useful thing we can do is that we can change value off pointer variable. For example, If I set point Toby to 20 the value off a will be 20 now you might ask, What is it good for? For example, Mellick function allocates space in memory. Mostly, it is used for dynamic size race where you passed the number of elements time size, off the data type. You won't and this function returns you pointer to some space in memory, and then you can work with this space in memory, and I will talk about that in following lectures. 23. C Pointer: Well, hello, Gas. In this lecture, I want to talk about pointers. So let me declare a variable cold Be and set it to them. Then I declare Pointer bowled a and l set it to the address of B. Right, So this a this ants the says address of B and this says it points to the address. Okay. And if I can just print bring this So I print B s now, um, in teacher values or some indeed, your value like this here I would be. And here I can bring the reference so you can see what the address actually looks like, though is now be as an pointer. And in here I pass a like this. And if I run this program, it says he is now 10 and is now some random sequence off characters, okay? And dad, it's actually address in memory. So now let me show you, Dad, When I change devalue that a is pointing to who by and here If I bring be again like this, the s now b is now five because this says that the address that a stored in a this side and the address that is stored in a is the B variable the base in memory where be lifts Okay, though it says b is now five. So dead way we changed the variable. And I can show you how it is useful in this increment function. Though sometimes we don't want to kind ah, as the value as the value. Okay, past arguments by value. But we want to pass a reference to some variable. Okay, So if I change this and if I change this, I have to use parentheses here because I increment. But if I call increments off address off B like this. Okay, I passed the address of be off this variable, and now I can just bring be ISS now and some in teacher value. Okay. Like this, though, B should be 11 because we passed the address, it accepts an address, and then it increments the value on this address. So then when I print be, this value should be 11. And if I run this program, you shall see it. It's 11. Really cool, right? So that is how we can. That's kind of address is okay. I hope that makes sense. Now let me show you stun maybe bit complicated stuff where I declare or enter to be I can also declare Pointer, do that pointer, Let's say, actually, pointer to do a okay and I write the reference to a so this might be reared, but it is useful in some cases. And now, actually, if I change, let's say or enter to a If I do the dear friends part two times, I'm actually changing. Be so I can do this. Set it to, let's say 20. And if I now bring be should be 20 and it actually says B is now 20. Okay, so yeah, that is how it works. This this is a bit complicated because this variable is pointing to a to address off A and A. The value on A is pointing to address off B, and we have the value off Then, though, yes, this this might be a bit complicated, so don't worry if you don't understand it right now and actually let me show you one last thing when you want to declare, um, dynamic Ray all right off some dynamic size. So let's say I declare variable cold size and I said it to four. I want four elements in this array. I can use Malik function and I can use it as a pointer. Let's see, my array, my array, and this will be equal to the result of Malik function where I passed Size times dies off Nice. Oh, inthe easier. Okay, so I have in teacher array that I have pointer to in teacher array that have or elements. Okay, so this Mellick function what it does, is it candor, Gramps, space and memory And it returns a pointer to the first kind of element. So now I can use this pointer and I can work with this as a regular array so I can write just my array on index zero is then I can do that, but I stimulating with other elements. Okay, like this And okay, this is getting a bit boring, though I fill it with some numbers like this and now I can just work with the array so I can, for example, printed using for loops. So And I equals zero because we are indexing from zero. Why I is smaller than size because that is thes size off our Mellick ated space. And I will be incremental. Each side's so then I can just bring the element like this. I am they face. And in here I just write my array on Index I though this will be friending all the numbers . So X ray let me and lie. And here, so yeah, this Lou will print it. 10 58 and two And yes, so extra. Let me around it so you can see it actually works then 58 and two. And now let me show you what happens if I kind of get behind your a So this Ray have Onley index for free. But now I will index on in next four. Okay, So I will be Samos eyes and we will still jump into this into this brained. Okay, so if I run this, you will see what happens. This is interesting, right? So what actually happened is that I kinda went to some place in memory and I don't know what well, you was stored in there. Okay, so, yes. So it might happen if you get I'm similar number. You probably looking behind behind your A or something like this. So yeah, that is how you can use Melo to allocate array, and that's pretty much it. If you have any questions, just ask in. I will soon extend. 24. Struct: now you know a lot of things. You know what is variable and how to use them. You know what its function, array and pointers. So now I will explain. Waris tracked. Let's say that we want to start data about person. For example. We are working on database of employees off some sort, and we need to soar Idea of employees, h, gender and celery. But there is no data type for all of these together. We want to have variable person, and all of these things have as a natural, viewed off this variable. Well, thanks to Struck's, we can do that. So Struck is basically collection off variables like Ray, but this time struck defines basically template off immune data type. So, for example, struck person would have these properties unsigned in I d. Why unsigned? Well, you cannot have negative I d right and variable off end date attack can contain even negative values. And but when we add on sand in front off end, there will be only positive values anyway. Another property would be age. And let's use your unsigned short because nobody will be older than 65,000 years, or at least not in the near future and by using short instead of end. We save space. Next one is gender year. We have more options. We can represent gender by bull, where one is men and zero is woman. But let's give with car gender where M will be for men and W for women. And lastly there is celery. So let's make it unsigned End again. And now we can create wary of a person, for example, both. And then we can set all the properties that we defined in this structure, and we will access these properties. Why are dot So, for example, if I want to set bops i d to 12 I can do that like this, so bop that I d equals 12th and I can said like this every property, so gender and other properties. And now I can create other, very ever off type person. Let's say Eva and then I can said her properties as well, and by setting Avis properties, bumps stays the same. So struck allows us to create kind of objects in C or in other words, declare variable that have multiple attributes, and I will tell you more in next video 25. C Structs: Well, hello, guys. In this lecture, I will talk about strapped. No. When I want to define new structure, I will just write struck keyword than there is this name off my strapped, then racist and Sema corn. And in here I write properties off my strapped like this. So in Teacher X and in teacher I right every point f it's x and I co ordinates. Okay? And now I can just create variables off points type like this. So I created a point a And now I can xs x by out this dot so I can set it to, let's say 10 and I can also said I 25 right using this dot i excess thes and these But anyway, I can also create a point B and I can initialize it. I can initialize all all the properties in here in these braces. So like this, for example. And this says that X is 10 and I is eight. Okay, though now I can just sprint the values so El Se x is, Then there will be I'm in Teacher and Iess and there will be other indie Jer Yeah, like this. And I passed their i a dot exe and aid that I though like this I can also do. I can also print be so you'll believe me. It actually works b and B And if I run this, you should see it works, right? So and be it iss excess then that's correct. And I was a So now I want to show you that you can still use pointers even with Struck's, though I can have point to see that points to a for example. And now I can set the I can said the properties off a Why are they see? But I will use that using this notation right, though. See this arrow? That seed this arrow x born sue this a x Okay, so now I can set it to, let's say one. And if I run this program, it will say a X is one. Okay, so that is how you can use pointers to change values And actually, let me show you what would happen if you write your a dart. So if I run this, you will see error and you recess then the left upper and points to strike to use the Cerro . It actually tells you what to use, though, if I correct this there's all right. No. Now let me show you, Dad. You can use this even with functions. So if I write here struck point as a returning type off, um, function, let's say at do points, though this function will take two points, Adam into one and return this one. So I jazzier another point or a and And that a point e And now I'll just create new point, though rock point result Okay, like this and I can just set set result that great result that X will be equal to aid that x plus b that X and same way with Why so results aren't I will be equal to a that i glass be that I and yeah, then I need to return result. So now let me show you that this actually works that it takes two points and puts them together into this one to this one, and it returns that. So let me get rid of this c and use that for dysfunction. So at viewpoints. And I passed there a and B and then I get to read off this line and I also brained see So like this Where? Right? See and see. So if I run this c should be 20 and 12. Oh, already though? Yeah, I can't count. Sorry, But anyway, the point is that it works. So yes, that's pretty much it. If you have any questions, just ask, and I will soon except 26. C How to get input from user: Hello, guys. First of all, let me show you how you can take input from user. So if I declare some integer variable, let's say a and I'll set it to zero and then I can the springs and and corral you inter number. Okay, so now I can use an f function. And actually, I need to use the cure version off this function Those skin f slash s and then I write what type I want. I want in teacher and the ref story. The address buffet. Right? So the address of variable that I want to I want to change. So now I can just brains. For example, you wrote, wrote and in teacher like a no like this. So what? This function does it it kind of Stubbs Deacons. Oh, and it takes input from user and it stores whatever user rights into this a variable, though Then I can just print you wrote the number he wrote. So if I run this, you shall see that it says enter number So else that I write many and hit enter and it says you wrote 20 so yeah, that's pretty much it. You will need this in the project that you will get into later on, though. Yeah, that's pretty much it, Alice. Soon extent 27. C Calculator: Well, hello, guys. In this lecture, we will create calculator. So the idea is that user passes for his number and second number, and we compute all the operation, right? So, yeah, we will need two variables A and B 40 number. That user passes. Okay. And then we're going to do is just ask user to enter some number, though. Enter first number like this and semi cone at the end of line. And then we will use skin function and the secure version off the skin function en re scan in teacher into a right. So we passed the address off a Oh, so we can do the same for Be right, 42nd number and thirst second number, and you re past the address of B. So now we have first number and second number. And what we're gonna do is we're gonna bring all the operation, though, bring death. And here I will write only righted like this. So in I plus and be will be equal to some other intelligence. No, like this Where this first this first integer will be a the second will be be and the last will be a Cosby. All right. Go like this and I right ish. And yeah, like this nd line. No, If I just be based it for every other operation there. There's five of them, I guess minus times. Divide on and go this on Dhere. I'll change it. Oh, so, um, we cannot just right Monroe like this because computer would think that. Hey, I he wants a number. This is This is indicating that here will be some variable. Right? So we need to write something called escape sequence and they just sells computer. This is not for number. We just want to print this percentile side, and we will do that simply by writing two of them. So this will help bring 1% ill side, but this is a bit weird, but it somehow works, so okay, let me run this. If by enter, first number, let's say Lenny and second number, for example. Six. I will get the results, and I believe they are cured, so Yeah, that's pretty much it. This is the first first project. I guess so. Yeah. I'll see you at the number one 28. C SumOfArray: okay, Gas In this lecture, I will show you how to grate some off or a function. So we accept some array, some pointer. We're a and then we accept some size. No, let's define some result variable and initialize it to zero and then we gonna loop. Road is array and every element Well, we gonna add every element to the result. And after this loop, we just returned two results, though if I write here for lube with I when we indexing from zero while I iss smaller than size because nice is like life and we have four elements. Okay, So must be smaller than size. And then we gonna increment i with each loop, though Now all we have to do is said the resolve into the result The grand result blasts they last the ray on index I Okay, we can also do it like this. So I commend this land and write it like this. So result plus equal ray on the next side like this so east to expressions are the same. Okay. And now I can just return the result like this. So actually this should work. So if I run this you shall see that it iss man 70. Okay. And it iss 70 like this. Okay, out ad just and line in here. And it works. So yeah, the idea is that we are going through all the elements in this Serey and we are kinda adding them to the result. Okay, So if you have any questions just asking, I will soon exam. 29. C Biggest number from 2 Arrays: Hello, Gas. In this lecture, I will talk about the solution off the task from previous lecture. Okay, though it is biggest number from to a race. And the input looks like first Ray Poynter than these size off first array than secondary and then size off second rate, these size can be different. And so we have to You've got in mind. So if I declare variable called result like this actually let me initialize is And then the idea is to go through all the elements in first, right big the biggest and then compare it to the all the elements in the second array. Okay? No, Now I can go just for in thes e equals 20 And until while I smaller Dan and I will increment I and Egypt oration. Okay. And then I'll just check whether do you resolve IHS smaller then the al amend on Index. I like this. Okay? And if it is smaller, ill said the result into Zelman because this element is bigger and we want the biggest number from first Toray. Okay, so yes. So after this cycle, I will have in result the biggest number the ISS number from room first array. Right? And then I need to go through the second array and do the same it so I can initialize I again. Zero. And while I smaller than m increment I And then if resolve is smaller than second, then elemental index site in second array. I'll just change the resolve into this Salman, that's they come in next side. Okay, So after this cycle, I will have the biggest number from these to a race, Gordon, result variable and I need to do is just returned this variable. Okay, so, yeah, if I run this, I actually go it. Call it. Lay like this in here though it should say biggest of to race ISS 45. And it says that though red, if you have any questions, just ask in. I will soon extend 30. C Get Random Number: Hello, Gas and this lecture I will explain how we can get some random number. No, I will include library called STD Lip like this Right in here is some function gold around and it returns as random number. So, for example, if I declare an integer value and I'll set it to the result of rent and then if I want wandered into to be in some range like from zero to use some number, let's say 100. I write it like this. It's so using this Modelo operation because this rent function in return, for example, 40,000 are even bigger numbers. So yeah, if I want number from 0 200 I use I use this, though then Atkins a sprint, Let's say a ISS now and in teacher and then an outpouring here A like this. And now, actually, let me copy this so you will see that they will be different because it is a random right. So if I call this rent function to times, it will return different numbers. Though it is 41 67. Okay, so yeah, that's pretty much it. This rent function is photo rent, though it is not actually like random because it is pretty hard to do something random on computer. But it's kinda, I guess, to have something to do with Glock. But I'm not quite sure right now. So anyway, if you have any questions, just ask in. I was soon exam. 31. C Guess Number: Okay, guys, in this lecture, I will create application. Something like small Game, I guess. And it is guest number, though The idea is that we generate some random indeed. Your number using the Iran function that I explained in previous lecture. Let's go. It's secret number, number like this, and it will be random number random in teacher from range and range from 0 to 100. Okay. And now, if I I'll, I will let the user say how many times you want to guess. Okay. And then how are D game? And if he gets the number he went, If he runs out off the guesses, he lose. Okay, so now let's ask user how many? Yes, this you want warmed on by this. And then I was actually I will define for some variable. So this will be number off. Yes, it's like this. And now initialize it and I'll use these can function in the Becker secure version of dysfunction and our and put some integer value into the number off. Yes, it is very ever like this. Okay, so now I have the number off guesses, and what I can do now is used while cycle Where our yes cycle. While number of guesses is Ray, they're down zero. OK, because when there is zero, we rent User ran out of guesses and he loses. Eso no, let me create another variable build Guess number and then will be the number that user Just guests though Now, inside this lube we want to ask user for a number Then we want to compare it to the secret number. And if it is equal user rinse And if it is not we d commanding number of guesses and go straight up here. So yeah, let me you that though I'll just ask Yes, yes, your number on here. I skin and into this into this guest number of variable. Okay, This number I actually need to use referencing here. So like this And then I compare the whether they get number is same. A secret number there, So better guest number is equal to secret number. If it iss we brand you win on. I guess you know I'm from Czech Republic. So it's not so great with English, but any way you want and yeah, and we break out of this cycle. Okay, Are you this And if it isnot equal, we determined the number of guesses. Rain number of guests. What's wrong? I'm grow guesses and we d commended. So yeah, that's pretty much it. This should actually work, although it doesn't say you news, right, And the end of the game, because when we break out of this cycle, user loses. So actually here we need to check whether the number of guesses is equal to zero. Because we get to this point even though, if user events, because we break out of this cycle and user winds. So if number of guesses as equal to zero we just sprained you, You lost like this and this should actually work. So let me try and run this and we'll see. Oh, some errors, though. What is happening in here? And that The rain typo. And if I run it again, it actually works, though how many guesses do I won't Let's say I want five guests, though I guess number and I know this number is from 0 to 100. So I guess and I was wrong, though actually, this is too hard. So let me now, at some future, though if the guest number is not equal to secret number. So, Elsa, I will give user a hint. Like, you know, the secret number is bigger or smaller. No. If his number smaller than Secret number I friend like e quit number is bigger. And now nd wide like this. Yeah. And else. Because if I get to this point, it must be bigger. The you create number must be smaller. Right? Because if it would be bigger way get here. And if it would be equal, we get here, right? So it must be smaller, and I'll just write it like this. No equally number is smaller. And if I run this program again, it should be easier to play. So how many guesses you on? I want five. Get this. And I think secret number is smaller. So I write 25 and it is bigger, so I'll ride, like, already thought It is bigger against, though. All right? Like 42. And it is smaller, though. All right? Like Bernie eight. And I lost that Suba. So yeah, that's pretty much it. At the end, you can say you lost secret number waas and then print the secret number like this. Yeah, but yeah, that's pretty much it. If you have any questions, just ask in. I will soon extend.