C++ Programming Tutorial 6 - Variable Declaration and Initialization

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's going on everybody this is video number six and the C++ tutorial series this video we're gonna be discussing variables and how to use them in our C++ programs before you started I would ask you to check out the sponsor Embarcadero C++ builder C++ builder is an IDE that gives you all the tools needed to create and deploy applications in C++ with this you can do drag-and-drop pixel-perfect UI's and with that you can deploy to Windows Mac iOS and Android so it's definitely a pretty cool tool if you're wanting to build real world applications I'll leave a link for you guys in the description go check them out you won't be disappointed the main point of variables is to store some value for us and then we can use that value throughout our program so what exactly does a variable look like first copy this example and then I'll explain each piece alright so we created a variable with the name or identifier of slices think of like slices of pizza here obviously and we assign it the value 5 so this equal symbol is actually called the assignment operator and it's how we store a value inside of a variable last thing here is this int this is known as the data type it's an integer 5 is an example of an integer similar to how we had return 0 down here and the function returns an int here well we're just creating a variable of type integer and it stores an integer value and don't forget that semicolon at the end altogether there's 5 pieces the data type the identifier the assignment operator the value and then the semicolon now what's going on here is actually a two-step process there's the Declaration and then there's the initialization so we could actually break these up into two separate statements and that's what we're going to be doing now so to do that what we could do is get rid of this equals 5 and just put a semicolon this is the declaration then we can do the initialization by saying slices is the value 5 so we assign 5 to slices now note we only use the data type when we define the variable the declaration says it exists and then the initialization says as a value in this situation we are assigning a literal value by literal I mean it's literally typed out in our code it's a 5 we don't always have to do that we could actually use an express so for example we could have 5 plus 1 which is an example of an expression now slices is going to have the value 6 and we can actually output slices in a C out by typing the name of the variable like so and there's no quotes you just type it plain as is and when we run this we get at 6 right here we can also assign from another variable so for example I could have a variable children and I can assign this the value slices now when we output children this is also going to have the value 6 there we go so slices was copied into children so now they both have their own values 6 they're not pointing to the same thing so I could set slices to something else and children is going to remain the same you can see it's still 6 so that is your introduction to variables we're gonna be using them throughout this entire series and you're never going to get away from variables in programming so make sure you understand these concepts if you have any questions or any suggestions leave a comment in the comment section below please be sure to subscribe and check out the next video because we're gonna be talking about how we can make our output a little bit more beautiful than just the 6 followed by my name so that's what we're gonna be doing in the next video template izing our output so check it out guys [Music]
Info
Channel: Caleb Curry
Views: 55,814
Rating: 4.9395018 out of 5
Keywords: C++, programming, tutorial, tutorial 9, beginner, code, variables, declaration, initialization, caleb, curry, calebthevideomaker2, variable declaration, c++ tutorial, coding, c programming
Id: vSTesJdgRCU
Channel Id: undefined
Length: 3min 51sec (231 seconds)
Published: Sat Jan 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.