[MUSIC] In this lecture, we'll talk a little bit more about variables. Variables are key, variables just like in algebra. You need variables to write code and we'll talk about variables and how they can be defined and what they mean. So variables, they're basically names that represent values in a program. Similar to algebraic variables, so just like in algebra, x equals 5, x equals y plus 2. You have these variables, x, y. They're names that are substitutes for certain values. All variables have a type, which must be declared. So type is an important concept in C and in most languages. The type of a variable tells you, basically, it intuitively tells you what kind of data it is going to hold. So for instance here, I say, int x. I'm saying, x is gonna be an integer, int is short for integer. Or I say, float y, I'm saying, y is gonna be a floating point number. So, I'm telling you what type of information is going to be held in that variable? Now the type is important, because it determines how arithmetic is performed and it determines how much memory is going to be used to store the variable. Because remember, all of these variables have to be stored in memory somewhere. And so the question is with a variable like x, how many bytes of space do we need to store that information? And with y, how many bytes of information? Cuz the machine when it's running, it has to store it, it has to know how big it's going to be. So that's what the declarations are for. If you say, int x, oh, x is gonna be the size of an integer, whatever that is on your machine. A standard 32 bit machine the integer is gonna be 4 bytes. Depends on the processor, but 4 bytes is standard for a 32-bit machine. Floating point might be eight bites something like that or I can't remember. Maybe eight, maybe four, maybe eight, but there are fixed sizes depending on the machine for each type. So one thing that type lets you know is how much memory is gonna be needed? But also the type tells you, how arithmetic will be performed? So arithmetic is performed differently depending on the type of data. So, integer. If you have an integer type and you want to do addition, everybody knows how to do integer addition, but floating point addition is a much more complicated thing. So if you wanna do floating point addition, actually what happens inside the hardware, inside the microprocessor is there's often a floating point unit, a dedicated piece of hardware, just there to do floating point operations. And it is separate than the integer operators, so you'll have an integer ALU, arithmetic logic unit, which performs integer addition and then you'll have some floating point unit that does floating point operations. And so depending on the type, you're going to have to send that data to a different piece of hardware to do the operations that need to be performed. Although floating point division is a whole other thing, you gotta a speculative dividing point, which is definitely different than a same energy divide. So that's why typing is needed. You need to know what type and all the variables are gonna be and so in C, you have to declare the type. So before you use a variable, you have to declare it. So before you can use x in your program, you have to say int x; somewhere or float y; something like that. So that's what variables are, you've gotta declare them in C. Now so there are several built in types, here are the main ones we're gonna look at. Char, int, float and double. Really, we're gonna focus on probably char and int. When it comes to embedded systems, we try to avoid floats and doubles, because floating point arithmetic and double worth or double is double precision point. It's slower and bigger, so we try to avoid them in general. Sometimes you need it, but try to avoid them. So an int is typically whatever the word size is, but it could be down to 16. So for instance with an Arduino, I believe an int is 16 bits, but a char. No matter what platform you're using, a char is only 1 byte. That's just a standard size. So actually, it's very useful. It's nice. When I'm coding, you use a char and you always know what you're gonna get. So, I often use a char by default. But floating point and double, they can be 64 bits, 128. They can be much longer. Now variables all have names, they have to have names associated with them. It's just a sequence of visible characters, there are some limits. For instance, it has to start with a non-numerical character. So you can have int testvar1, that's legal, cuz it starts with a t. But you can't have int of 1testvar, because it starts with a 1. So that's not legal. You can't have any variable names that are C keywords. If, else, while, that sort of thing. So there are so limits on variable names, but you have wide discretion in what your names are going to be. Thank you. [MUSIC]