[MUSIC] [SOUND] In this lecture, we'll talk a little bit about the basic c operators. All the operators that you perform. That you'd regularly execute in an instruction that is in c. The basic ones, anyway. Basic arithmetic and logical operations. These operations are very common. You see them in all languages, virtual unchanged in different languages, but we'll go over them. So first there are constants. You can define constants, there are actually a couple of ways to define constants, but we'll talk about #define. #define is a compiler directive, again its got a hash sign in front of it so it's a compiler directive. And #define basically substitutes one string for another. So, like here I say #define answer 42. So what it does is wherever it sees answer in the file, it substitutes that with 42. So it's just a macro substitution. It says, oh I see the word answer, I'm gonna stick a 42 in instead. Very simple. It happens at compile time, I think before the compile, so the pre-processing step. It just looks around for every time it sees ANSWER and substitutes the 42 in. You can do this with characters. In that case, it was a number, the number 42. You can do it with character constants, too. In this case, if you want it to be a character, you gotta put the character in single quotes. So #define TERMINATOR 'x'. Notice that I put the x in single quotes. What it does is, if you put it in single quotes it knows that it's a character and it interprets it as a character. So it interprets it as an ASCII character or Unicode really. So ASCII and Unicode, what they are I haven't described them. But what they are is every character. Visible character or an invisible character. Every character you see on your keyboard for instance and lots of other characters you can't. They're all mapped to numbers. So, X might be 41, Y might be 42, and so on. They're all mapped to numbers in a table. If you Google ASCII table, ASCII characters, you'll get a table that lists every character and its ASCII code number. Or Unicode is a bigger one. So ASCII is only eight bits long. Really seven bits. Unicode is 16 bits. So you're gonna have a lot more characters. But ASCII and Unicode overlap. So lowercase x has a certain representation, a certain number. And if you put it in single quotes like that it will know, oh this is meant to be a character, so I will represent it with this ASCII value. You know, and it looks it up in the table and stores that some characters are not easy to represent, meaning they're invisible characters, like a bell character which, actually, in old machines used to make a beep sound when you'd click it. Control, kind of, it's been a while since I've used such a machine. But there's a control keystroke. Control something, it would make a beep that, you can't see it, all right? It's one of those invisible characters. So if you wanted to represent that as a character, you can do it But you have to give the ASCII code number, which is not something we're gonna necessarily get into. So, they're constants and you can use hash define to define those. Now, C has a set of arithmetic and relational operators. Standard stuff. So, plus, minus, times, divide, all that. The percent sign is a modulo operator. So, modulo is the remainder after division. So for instance, 9 module 02 is equal to 1, because if you do 9 divided by 2 you get 4 and the remainder is 1 so 1 was returned. Or 9 module 03 is 0 because 9 module 03 If you say, and I divided by three and you get three perfectly, there's no remainder. So zero is the remainder. So module is basically the remainder. Plus plus is an increment. So if you want to take a variable like x and increment it, you say x++. If you want to decrement it, you say x--. There are comparator operators, relation operators. So equal equal. And actually this is something to be careful of in C. And other languages. If you say x equal 1, that's an assignment. That assigns x to be one, but, if you say x equal equal 1, that is a test. It's a relational operator. It returns true if x is actually equal to 1 and false if it's not, okay? So you would use x equal equal 1 if you have an if statement, like here take my if statement down there. X is less than 5. So if x is less than 5, do whatever, right? So in that case you're using a relational operator as a test. So x less than 5 returns true or false. True if x is less than 5 and false if it's not. So == is a relational operator, it's a comparison which returns true if the two things are equal, false if they're not. And they're used in if statements commonly and conditionals and so forth. And so those are the common relational operators. All the common relational and arithmetic operators. Also, you have logical operators. So logical operators meaning and, or, not so boolean logic. So for instance, ampersand ampersand that's an and, bar bar that's an or and exclamation that's a not so what happens is these operators treat the arguments as one bit binary value so So AND, take AND, &&. The arguments to that operator on the left and the right. So you might say 1 AND 2, 1 && 2. Let's say we did that. So it has two arguments, 1 and 2. These two arguments, it treats them as one, big, binary value. So even though 1 and 2 could be integers, and have many bits, it says, look, I'm gonna say you are either true or false, 1-bit binary. And the way it does that is it says, look, if it's zero, whatever the value is, if it's a zero, then that's a false, and if its anything but zero, then its a true. So if I said one and two, it would say one is true and two is true, and then true and true is true, so it would return true. Okay, because one and two are both non zero, so they're both considered to be true. So for instance this statement, if A is equal to one and not B. So first thing is if you look at the and it has two arguments. The left side is A=1, so that's true if A is equal to one. And false otherwise. Then the right side, the not B is the argument. So, not B is gonna be true if B is false. So if B is equal to zero, then not B will be true. Okay. And if both of those things are true, if A is equal to one, and B is equal to zero, then the if statement will evaluate to true and it will execute whatever it's supposed to execute. So that's how logical operators work. They take the arguments and treat them as either true or false, just like a 1-bit bullion value. Thank you. [MUSIC]