C++ Tutorial – Learn About VARIABLES

ACCESS the FULL COURSE here: https://academy.zenva.com/product/cpp-programming-bundle/?zva_src=youtube-c++-programming-bundle

TRANSCRIPT

What is up everyone and welcome to the fifth tutorial in our “Learn C++” course. This will be on variables, and is part one of two just because there is quite a lot to take in with regards to variables, and I don’t want to overwhelm you with everything all at once. So in part one, we’re going to focus on what are variables. Then we’ll talk about some of the basic variable types in C++, these will be in the slides, and then we’ll turn to the code and focus on assigning and reassigning variables with some examples. So for starters, what are variables? variables is simply a way to store and modify data within a program. Pretty much every program will need some kind of variables to help maintain its state throughout its execution. Variables can be used temporarily or can exist throughout the entire program’s execution. Take for example a game, often they’ll ask what your name is right at the beginning, and then they’ll store it somewhere. Well, that name will exist throughout the entire time that you’re playing the game, and also in future runs as well. However, if we’re entering, let’s say a specific level, there may be a lot of variables that help set up the level that are basically destroyed, as soon as we leave the level or go into a different one. Now, each variable uses a “type” to dictate the kind of data that can be stored. So there might be, let’s say, numerical types of variables, well there may might be text based variables or true false variables, these are all determined with the type which we have to assign. Creating a variable can be broken down into two stages; declaration and initialization. Declaration is essentially assigning a type and a name to a variable. And then initialization is storing a value in that variable. So some of the types in C++. For starters, C++ is statically typed. So statically typed means once we assign a type to a variable, that type can never change. If we create let’s say, a numerical variable, we cannot then later store a true or false value in it. Now this is unlike languages like Python, which are considered dynamically typed, those definitely allow you to modify types of variables, but C++ is a bit more rigid that way. So some of the basic types we might encounter will be Booleans, which are true or false values, integers, which are positive or negative whole numbers, floats and doubles, which are decimal numbers, characters, which are single byte characters, and then there are null pointers and void types. Now, null pointers and voids are a little bit more advanced, so I doubt we’ll actually cover those too much in this course, but I just wanted to include them here just in case some of you say, “Well, there are actually other types and you didn’t include them.” Okay, so I think we’ll focus on bools, ints, floats. We might take a look at some doubles, but we’ll kind of skip over those for the most part because they’re actually quite similar to floats, and the characters and strings, we’ll actually cover in the next tutorial. So let’s head on over to the code and go over at some examples. Okay, so as you can see, I’ve kind of cleared out my main file and put everything in old code. And I’ll continue to do that as we go. All right, so the first stage is going to be talking about how to declare and initialize variables. So the two stages are gonna be assigning a type and a name, okay. So that will be the declaration and then initialization will be name equals some value, okay. We can do this in two steps, or we can do it in one like this. So let’s focus on Boolean variables, because they’re the simplest. The type is gonna be a bool, okay? The name is gonna be whatever we want. Let’s think about something game related, so maybe it’s something like “isGameOver”, okay? And then we can leave it at that. We can then assign it in a value. So isGameOver is equal to false because maybe the game is still running, okay? So Boolean is perfect for this kind of a variable, because the game is either over or it’s not over. So even if it’s paused, that doesn’t mean the game is over it’s technically still running.

Free Tutorials:
– Unity: https://gamedevacademy.org
– Phaser: https://phasertutorials.com
– Machine Learning: https://pythonmachinelearning.pro
– Web Dev: https://html5hive.org
– Android: https://androidkennel.org
– Swift: https://swiftludus.org
– VR: https://vrgamedevelopment.pro

Post Author: hatefull