 So you guys want to learn C++ and you were wondering yourself how the hell do I learn C++ just the basics I have no idea how to code at all I don't know what I'm gonna do and what am I gonna do to just learn C++ So you find yourself all right What am I gonna do? Well the first thing I'll do is I'm gonna go online and I'm and I don't have any compiler I have nothing really to be honest. I have like nothing no compiler nothing So, how do I get started? Well, the first thing you do is you type in online C++ compiler and You click the first thing that you see Online gdb right and then it pops up all the stuff that you have no idea how to do and You don't know what you're gonna do to get started So well what this video is gonna tell you guys is how are you gonna learn C++? And what am I gonna do to teach you to C++ and in fact, how can you learn C++? All right, so this is gonna be this video series is gonna be teaching you guys the basics of C++ for someone who has No idea how to code with someone who has no clue and just got started So you just opened up a basic C++ compiler Now you're thinking to yourself how the hell what what are all these things? Well for starters C++ the code has to run something right? So let's actually just just like delete everything cuz screw this and let's just start with the basics So here we have main dot Cpp. All right. Now if I just run this technically It's not gonna do anything right? It's gonna give me errors cuz like first of all it has nothing to do It's not gonna do anything right cuz we don't know what how would the how's the code gonna start if there's no code there Right so what does the program need to do the program needs to start somewhere? So where does it start? code starts in main This is the starting point of all C++ code at least most of the time All right, so it starts in main. What is this main? Main is a method or function where it starts where the program starts and it's gonna run from start to finish Well, first of all if I try running this what is it gonna do? Well, well, it's just finished right program finished with exit code zero exit the console But I but I can't do anything right. I can't do much here. It doesn't tell me anything. It's just into main Right. No, you might be wondering yourself. What is this int? What is int? Well in C++ encoding we kind of just want to We want to put abbreviations over everything, right? Because if if you don't if we don't if we don't abbreviate anything, it's just harder to type things So in just like in computers and just like in math in the world in general, we have integers, right? There's numbers. How do you represent numbers in in computers? They're integers. So what does int represent? Int is just short for an integer Okay, so now my unit guys might be wondering what is into main then what is the point of into main? What is the point of this? Well main is where the code starts, right? I just told you guys it's a function It says it's a function where the code starts and it ends and why do I have these curly brackets? These curly brackets tell me where it's where my function they're gonna start From main and where it's gonna end in main, right? These curly brackets the first starting point a left curly bracket last starting point right curly bracket These are braces now think about this Functions just like functions in C++ and just like functions in math remember Functions in math in an algebra or a geometry or grade school. Well, what are functions? They start they take an input and they return an output, right? If I said like a function y equals two times x, right? I pass in an x value and I spit back out two times x. That'll be your y value. Well, that's the same thing in programming Main is just a function that tells you something now Ideally, it's what has to return something right because I took in an input. It has to return an output, right? Now here I didn't have to write any output or input and it just ended because I don't know That's just how the compiler works here But ideally in most C++ code you have to return a number because it's an integer, right? It's an int main. I'm returning an integer. This is the return type Return type is an integer. So ideally if you want in C++ when you want to return something in main, we return zero Why do we return zero in C++? Zero is represents. I executed fine, right? I do any other number like one negative one stuff like that means you An error occur normally like I said failed. So this is what it does, right into main It's just a function that starts your program in main and it just returns zero now if you were to run this It just it doesn't do anything, right? If program finished executed code zero So now you guys might be wondering well, how am I gonna? How am I going to actually print anything? Right? I want I want to have fun in coding, right? I want to print something to the screen I want to do stuff. Well, first of all Unless you write your own print function or you are at your own Input and output function the code is just a code, right in this file The only thing that the program and the computer sees is just everything in this file So if I want to actually print something I need to write code that actually prints it or I could import import Code that someone else wrote that prints out to the console So that's what I'm gonna do in here I'm gonna import a code Include a code that someone else had already made for me so I could print out to the console Otherwise the program doesn't know where to run and it doesn't know how to print things out to the console screen So what am I gonna do? I'm gonna do hashtag include put these left Last-hand sign greater than sign and I'm gonna do I oh stream and what does I oh stream represent? I oh stream represents input output stream Input output stream just means I'm gonna print out to the console and I'm gonna I could read in values from the console So that's what this represents. So here now now I have code right now I have the code that allows me to read in values and print out values so Now in in C++ a lot of your code is structured in these things called namespaces Which is like it's like a con conglomeration of code, right? So if I want to print out something to the console I need to basically declare Get my value the mother code that I have for my namespace of where the print out To print out values of it and then use that as a way to print values out to the console So in that case the namespace we're gonna use STD. I don't know why they call STD But that's just how it is. So what how do I print values out to the console simple? It's called see out. So I have STD colon colon see out Now I could print any value. I want out to the console. So I let's say I want to print out 10 Then I'm gonna use see out less than less than 10 and I'm gonna put a Semi-colon is in Programming semi-colons are the ways you end your statements. They help you end your statements So if you have your semi-colon it means you're basically you ended your statement Now if I run this click around is it's just gonna print out 10 Now what if I want to print out 20, right? What if I want to print out 20? So I'm gonna do STD See out 20 Right, I want to print out 20 and then a print out 10 10 and then 20 if I run it Well, it's actually gonna print out values side by side 10 and then 20 and why does it do that? well because in the Program's eyes it basically just said I'm just gonna print out 10 and I'm print out 20 But as for me, I want to actually print out new lines, right? I want to print out a new line So in order to do that, there's another way to do it using the console statement and that's called We're gonna use lesson lesson and L And L means end line at least how I think it is It's just gonna end the line from where you're at and it where you're just going to start to the next line So now if I run the code again Well, whoops, what did I do wrong and L was not declared? Let's go. Oh, whoops my bad. It has to be STD and L. Yeah Yeah, then we then we could print out 10 and then 20 and it does it does its new line So why does it why do we need and L because why do we need STD because STD is a namespace? For we need to get our values of our code from in order to put things out to the console statement So that's why so now what we could do also in C plus plus is that if I don't want to rewrite the same namespace rewrite this This library or this thing to import my code in over and over again. I Could use something called using STD using namespace STD so then what this is going to do is now I don't have to Repeatedly write STD over and over again From the area that I am printing out to the console statement So now if you see this a I don't have to write STD over and over and over again So that's the thing. That's what allows us to basically allows us to print things out to the console statement Okay, now you might be thinking to yourself. Well, this is really boring. All I could do is just print things out to the console Well, you see there's 1020. I only could print things out to the console. How this is is that all there is to coding? Well, not really that you could also read in values to the console, but to read in values. How do you read in values, right? Well, let's think about life. I should think about life. All right, so if I imagine myself just Want to represent anything in life as something in a computer screen, right? Well, what do I have? What can I do if I want to represent things? Well, I got numbers, right? I got numbers I could represent them as Interiors 1020, but what if I want to represent values like I don't decimals, right? How to represent decimals? Well, it's pretty hard to represent decimals You need a you need a dot right need a dot to represent decimals So just having numbers integers. That's not gonna help you. So what do we have? We have something called floats float Float is basically just the same thing as an integer except now you have decimals So if I want to create a value for I don't know a variable, we're gonna create a variable Float Let's create a variable right just like in math Variables are ways to help you store values. All right. They're basically they help you store values for your Your anything that you want in C++. So just like in math, we're gonna store values So let's actually create a variable. We're gonna call this float X. It's gonna equal to I don't know a lot of 12 3rd 12.3 12.4 it or whatever Now now if I just do see out and I print this float it should print out 12.4 when I run it Boo, yeah 12.4. So print it out 12.4. So now now we think about ourselves. Well, now we have integers and we have floats But what about things that I need? Right? What about like There's other things I need to represent in life as code, right? And what is that? Well, there is something called Booleans What if they're what if I want to represent things like true or false, right? Things that are on or off something something could be true something could be false Well, we could represent that that's called Booleans. So now we have Booleans in C++ We call this a bool. And what is this? Let's actually create a variable. I'm gonna create a variable That's called. I don't know why Right, we're gonna set this variable y is gonna equal to a value and Booleans are just true and false So I could set this as true Or I could say that's false. So now now when I print out my My values for my Boolean it should tell me What it should print out my Boolean values. So I'm gonna print out now. I'm gonna get rid of this x, right? So I remember I had 12.4 before now. Let's actually print out. Let's just print out y All right, I'm gonna print out y and a print out a new line. So let's see what this does Okay, so what's weird, huh? That's weird so here I created a variable called y and I said equal to true and then I printed out The value of y after I printed out the value of x. So why is the value of y? True equal to one right I print out why this should return true So in C++ anything that is not zero is called true Okay, it's kind of weird. I know it's weird anything. That's not zero is basically true So if I had like five I don't know five. That's technically considered true eight is could technically consider true. But yeah, so Yeah, so now we basically I basically explained to you guys how to create variables and Basically these types different types already. So let's go back to the gist of creating variables. So here we have How how do you how do you create a variable? Well, you you tell the type you wanted to have which is like floats Or Boolean or integer then you give the name of the variable. So this is going to be the name of the variable I call that x and then we set it equal to a value. So equal to a certain value 12.4 12.5 13.5 Whatever it is and that basically just tells you how to create variables So now we have Boolean, which is true or false. Why they're gonna tell you true or false So what other type of variables can I create? So we have currently we have True and false, right? But what if I want to have like Put out like, I don't know characters, you know, I mean characters like the alphabet English alphabet How do I write that? Well in C++ we abbreviate characters as char. So here we have char and Let's name it. I don't know Z And I'm gonna say equal to I don't know the character Z So this is how you create a character in C++ Create a character variable called in C++. So we're gonna do char Z is gonna equal to These are Single quotations. So in kit for characters, we have these single quotations that basically just tells you hey This is a this is a single quotation. So this is a character And if we were to just print out Z now see out Z, it should just give out Z Yeah, so we have 12.4, which is our value of X See how Y which is one And then we have Z which is just prints out Z. So that's basically the gist of this. All right That's the gist of creating variables So yeah, once you create a variable you could have Once you create a variable. It's a it's you created a variable you could print it out now Now let's get down to it What if I want to Have a multiple If I want to change the value of a variable, right? So here I've float X is equal to 12.4 Right so here I'm gonna get rid of the printing out the values of X and Y of Y and Z so here we have Float X equal 12.4 Now, what if I want to change this value? Well, it's easy. I want to change the value of this variable I just said X is something else. Let's say X to 15.7 or something, right? Now then I just have to print out the value of X again and The value of X changes, right? Here we have 12.4 and then now it becomes 15.7. So that's basically the how you do variables Variables you could change things you could change things in the middle of it. So like that Now what if I don't want to change this variable? Well, like at all, right? Well, first of all, you don't use what you could do is you could just not Said it not change at all like not set X equal to something else But what if I want to force people to not ever change it like I wanted to remain as 12.4 Well, some people want to do that and if I want to force people to not change this change the variable X What am I gonna do? I just put constant in front of it Constant means constant. That means it will always be constant This constant Float X will always be 12.4. So now when I change Try to change to 15.7. It should throw an error Yep boo, yeah Now whenever the anyone else wants to change this variable X. It's gonna throw an error. So then you can't change it Now the value has to be 12.4 forever Right. So after when I print out X this float variable X is always gonna be 12.4 So you can't do anything anymore All right, your variable is just gonna be stuck here forever. All right And you could do that to the same for any of these values actually you could do this constant Y Cons for Z you could do do this for all the characters anything you want. It's now constant So you can't do anything you can't change this Y if I want to set Y equal to false It's gonna throw an exception It's going to give me error False it's read only so you can't change anything So I basically explained to you guys the basics of floats bullions and chars But what if I want to print out like a whole whole list of characters, right? Whole list of characters like char is the Z. Well, I can't just If I try to like put characters together, it's not gonna allow me to do that. So in C++ We can't actually Put more than one character together. So if I do char Z is a character Z What if I want to print like Z Y right Z Y put Z Y here Ideally this it's not gonna allow you to do that If I print Z now Should throw an exception. Oh wow Yeah, oh well it finished but it didn't Had this weird thing here squiggle line so characters in C++ for a char Z Only allow you to have one letter. Okay one character. So one letter The alphabet. Yeah, so on and so forth. It doesn't allow you to have more than one Character. So what do you do that? So in C++ you could also use something called strings which are basically just Multiple letters concatenated together. Alright, so the multiple letters put together. So here if I want to include a string I'll just do include string and Then it should have now allow me to Have multiple characters. So now if I want to create a string. So string Multiple letters, right? I'll create a variable called multiple letters. Now. I could actually Create a have multiple letters. So I could do have a Z A B C D F G H I J K so now When I print out print this out It should allow me to have Multiple letters. Yeah, see A B C D E F G H I J K You print it out in the end here. So Care here's a big careful When you do difference between strings and characters. So and for characters Like right just one single character. You have only have a single quotations, right? See this single quotations for multiple multiple characters for strings It's double quotations double quotations. So you need to use that. Alright Okay, so basically guys, I just explained to you how to create variables and yeah now I Think I did go over the functions, but let's Let's actually do some more functions actually. So let's go over some functions So remember we have in domain, right? This is the main function and it returns an integer Right and here it returns zero and that basically just tells the code Program that hey I compiled successfully. I'm just gonna return zero and zero means I'm just gonna finish After this main, but what if I want to print out another function, right? What if I want to write another function? Well simple What if I have like I'll just do the same thing. So first I have to specify what type of function is So it could be float Boolean character. I don't know. So let's say I want to do float Let's say I just want to do I don't know To okay, so in this float, I just gonna return 2.5 or something. So then this function float to Actually, let's do float to five Right, this function is gonna have is gonna return a float a variable float and it's gonna return 2.5 And if I want to print this all I have to do is I'm gonna do see out print this function And now I should have 2.5 afterwards. Yep 2.5 2.5 So you now you might be wondering, okay So now I have a function that could create functions and return values for the function But what if I want to take an input, right? So remember in math like basic math that you functions take an input and then it spits out an output, right? So I have like let's say I take an x spit out 2x Y spit out 2y or something. I don't know That's the same thing in C++, right? So Here what you could do is you could actually in these these parentheses These left parentheses and right parentheses this parentheses actually tells you what the inputs you want for your function So here if I want to input, I don't know integer an integer variable x and I just want to multiply return 2.5 times x right I just do return 2.5 times x So, yeah so in C++ These are multiplication, division, addition, subtraction all work. It's the same thing how you would do it It would just be like Here this would be division This would be plus, this would be minus Let's multiply. All right, it still works the same thing as a regular regular things. So now if I Try to run this it's gonna give me an error Why is there giving me an error because this function to five requires an input input variable of x and it's returning 2.5 times x and Here when I'm just printing out to five. I'm not actually inputting anything. So that's why it's giving me an error So if I want to input something, I don't know what am I gonna do? I'm just put like any number I guess so here what I could do is I could create like an any and a variable called a I don't know to It's just gonna have a value of two so integer to have value two I could just pass that variable into this function and then it would just spit me out 2.5 times by two. So that will give me five. Okay. I know thing I could do is I could do I Could even put like the actual numbers. I don't have to put in variables. I could do like three and It's it's and if I print out two five three, it's gonna do two point five times three So, yeah, it would give me a seven point five So it's basically the gist of functions Functions allow you to basically take an input and it's spits out an output. All right, that's basically in functions now What if I try to move this function down Underneath main so I take this and move this and put it underneath me. What would happen? I run it Gives me an error. Why does it give me an error? 2.5 was not declared in the scope. All right. So what is the issue with this? The thing in C++ is that when it reads something it reads it from top to bottom It reads in the code from top to bottom here It what it's doing is it's gonna read in all these this line by line and it goes to main It starts from main goes through all this code then it says, hey I'm gonna run 2.5, but 2.5 does not exist. So it throws gives you an error Throws an exception. It gives an error. Why doesn't 2.5 exist because my function that I wrote Here is below the main function. So when it's reading through line by line going down to 2.5 It doesn't know where 2.5 is yet because the 2.5 is underneath main So that's an issue So how would you fix this? Well, there's two ways to fix it One way is to always have all your functions to be above main. So I could put all my functions above main If I run it, it'll be fine, right? Because it's gonna read in from top to bottom and it reads and hey, there's 2.5. There's a function 2.5 That's all right, and then it goes down to main main goes down to main It starts executing go goes through all these lines line by line by line and then it hits 2.5 It realizes. Hey, I've seen 2.5 before it's on the top I go to the top I print out my functions and my values I return the values and it does that But what if I don't want this? I what if I don't want to have all my functions above main? How do I do that? Okay, whoops my bad. So here let's say I have a function below main. What am I gonna do? simple thing you could do is You could say Hey I'm just gonna declare a function and I'm not going to have any Tell you tell you anything, right? I'm not gonna tell you anything what it is what's inside of it and then until it reaches to the bottom of the code Then I'll tell you something You could do that What do you do to fix it's what this is going to be called prototyping Basically what I'm going to do is I'm just going to copy the first line of the function the top of the function So like float to five integer x just copy this and put it above main Then I'm gonna put my semicolon This is going to be just declaring that hey this function exists to five exists I'm not gonna tell you what it does yet until it reaches to the bottom, but just know that this exists and then When you do hit it, you could just find it find it in the bottom Anywhere in the line in this file. So now if you've run this It the code does run Okay, so now basically if you want to Put functions below main all you have to do is you just have to copy the first line of the function function name Put it above your main method and put a semicolon and then it will just tell you what it is This is called prototyping Basically, the prototyping is just copying the function signature and putting it on the top So what is the function signature function signature is just then return type of the function the name of the function and the Inputs the parameter inputs that you pass in That's what it is. So yeah I hope you guys enjoy this video. This is just a simple quick beginning video on Functions and variables. I know my previous C++ tutorials were not very cohesive and not very it was pretty difficult to understand but now this is for beginners and I'll help you guys learn C++ right calm subscribe. I'll check you guys later. Peace