 Hey everybody, it's Brian. Today we're going to be discussing variables and data types. I'm going to make the assumption that this is not your first programming language, and if it is, I'm going to beg you, go learn a different language first. C++ has an incredibly steep learning curve. Go learn Python, Java, Visual Basic, C-Sharp, and then come back. Okay, moving on. A variable. A variable, as you know, is simply something that changes. It's a declaration you make that you have this thing, which we're not going to define yet, you have this thing, and that this thing will change. A good example of a variable would be age. Your age will change. Now a variable can be typed. What I mean by that is these are the different types of variables you can have. There's many, many more, but these are the basic ones. The fundamental data types, if you will. Character. It's basically one character, like the letter C here. If I could highlight it, the letter C here is a character. In C++, a string, this is just an array of characters. We'll get into that into a different tutorial. You can see it's one byte and it can be signed or unsigned. What does signed and unsigned mean? Well, signed, which all variables are signed by default, means that it can be negative. You see negative 128 to 127. Unsigned means 0 through 255. It still has the same range, but notice that one can be negative and one can't. Whenever you see unsigned, just know that it means it can never be negative. If you try to give it a negative, you're going to get some weird number or a compiler error. Your program will just crash. Short int. This is a small integer. If you come from Visual Basic 6 land, that's the standard integer size. Int. That is a bigger number. That would be like an equivalent to a VB6 long. Long int, which is a massive number. Bulls, those are like light switches, just true or false. Float for floating point processes. For example, video games use floating point to determine the trajectory of the grenade you just threw. Floating points are not accurate. They're only accurate to a certain number of digits. You see this approximately seven digits. It's accurate up to about seven digits. Double precision floating point number. Long double precision floating point number. W care underscore T, wide character. What is that? I believe W care underscore T is a unit code. Correct me if I'm wrong, but I believe that's a unit code. Those are the basic data types. You notice size is very important. Why is that? Well, C++ is cross-platform in theory, but in practice it can get a little tricky. For example, an integer is four bytes, so it says, but on some systems it's actually six. Some systems it's eight. Some systems it's four. You can't really depend on the size being constant. If you're going to do cross-platform programming, which our tutorials intend to using the Qt framework, you should use a framework that is intended to be cross-platform. Otherwise, you will run into some size issues with your variables. Now, without further ado here, we've got our basic template. I've already added some code. As you can see, we've got an unsigned integer age. Remember, unsigned means it can never be negative. Int, eggs, this is a sign. Remember, all variables are signed by default six. So let's just play around here. Cout, age, and we're going to just add an inline here. And then we're going to say age equal negative 23. And then we're going to say Cout, age, and L. So we're just going to print two lines here. And after the first line, we're going to actually set age to negative 23. And I know you're sitting there saying, hold the phone. We just said age can't be negative. Why are you doing that? Well, I want to show you what happens. There's a common programming mistake with variables. Let's run this. There's some errors. Undeclared identifier, Cout. What the heck? Okay, I see. Sorry, guys. Long day. Let's run this again. Now, we've got some interesting results here. Zero and, well, it looks like four trillion. Where'd that number come from? Well, remember, age can't be negative. So what it does is it goes to the largest number and counts backwards. So let's try a short int, unsigned short int. Let's recompile this and see what happens. Notice how we've still got this number, but it's very big. It's not a negative. Well, it's because it went to its maximum range. Let's flip back to our types here. We got short int. 65,535. 65,513. So you might have guessed it went to the maximum and reduced it by 23. That's how it works. So if you're working with your code and you get some really weird numbers, check to make sure you're not passing a negative. Other than that, it's just very standard. You declare signed or unsigned. You give it the type. You give your variable a name and then you set the value. Now, what happens if your value hasn't been set? Run time check. The variable age is being used without being initialized. We didn't initialize a variable. Therefore, it technically doesn't exist, so we can't use it. Well, I know this is kind of a short tutorial. I just wanted to let you guys know how variables work in C++. Like I said, I'm making the assumption this is not your first language, so this should just be a very quick review for you guys. This is Brian. Thank you for watching. I hope you found this video educational and entertaining.