 This is in continuation with my previous video on introduction to pointers. By now, you should know that a pointer is nothing more than a variable used to store a memory address and a pointer can be declared to store the address of a specific data type. In this session, we will learn arithmetic related to pointers. Like other variables, pointer variables can also be used in arithmetic expression because pointer is an address, which is a numeric value and on numeric values arithmetic operations can be done. But there are some limitations. We cannot perform every type of arithmetic operation with pointers. Pointer arithmetic is slightly different from the arithmetic we normally use with other variables. In this session, let us learn which arithmetic operators can be applied on pointer variables and how they behave. Also, we will see how to use arithmetic operators on pointer variables in a program. To understand this lecture, learners should have basic understanding of operators in C and pointers in C. As I said earlier, pointers can be used in arithmetic expressions as their numeric values. Let's see some rules regarding pointer arithmetic. Pointer variable can be assigned a value of another pointer variable provided there of same type. For example, integer star p star q. So, p and q are integer pointers. They are capable of holding the address of an integer. X is a integer variable. We are storing the address of X inside p. Then q is equal to p means we are assigning the value of p to q. So, assignment operator can be applied on pointer. Pointers of same type can be compared by using relational operators. Relational operators such as equal to equal to less than and greater than. For example, if p and q are integer pointers, so we can have a comparison if q is equal to is equal to p. Means a value stored inside p and q whether they are same. Four arithmetic operators can be used on pointer variables. Increment, decrement, addition and subtraction. Prefix or postfix increment or decrement operators can be applied on pointers. Means p++ can be done similarly q minus minus can be done. An integer value can be added or subtracted from a pointer. So, p is equal to p plus 5 is a valid operation. Similarly, q is equal to q minus 2 can be done. So, here we can add or subtract some constant value to a pointer. Now, let's see what cannot be done with pointers. Pointer variable cannot be multiplied by a constant. Similarly, pointer variables cannot be divided by a constant. If you try to do that, it will give you an error. Now, let us understand all these arithmetic operations with the help of program. Let's see how one pointer variable can be assigned a value of another pointer variable. This is code block environment. In this program, we have declared one integer variable i to which we have assigned a value 50. There are two integer pointers p and q. So, p and q are capable of holding address of an integer. p is equal to ampersand i. So, we are storing the address of i inside p. Then q is equal to p. So, we are assigning the value of p to q. Now, this program is printing the value of p as well as q with the help of %u. %u is a format specified for unsigned integer and addresses are unsigned integers. Then we are trying to print the value of i with the help of p and q. Value of i is equal to %d star p, means value at address which is stored inside p. So, it is going to print the value of i. Similarly, with the help of q, we are trying to print the value of i. Now, let's see whether this value of p is being assigned to q or not. Now, let's run this program. Here you can see value of p is 6356740. So, this is the address of an integer variable i. So, same address is stored inside q because we made q is equal to p. Then value of i is 50 and again we are printing the value of i with the help of %u. So here, value of p is being assigned to the pointer variable q. Now, we are trying to compare whether p and q contain the same value. If p is equal to q, both pointing to the same location, otherwise they are not pointing to the same location. Let's run this once again. Now, here you can see both are pointing to the same location because we have used the relational operator equal to equal to. Now let's see another program in which we are going to see how increment and decrement operators can be applied on pointers. Here also, there is an integer variable i to which value 50 is being assigned, integer star p. So, p is a pointer variable. Inside this pointer variable p, we are keeping the address of i. Then we are printing the value which is stored inside p. Now, we are writing the expression p plus plus. p plus plus means p is equal to p plus 1. Whenever a variable is incremented, one is getting added to that variable. Now, let me ask you a question. If the address inside p is 3000, what value shall we get when we increment a pointer? That is when we do p plus plus, what will be the value stored inside p? Will it be 3000 plus 1 is equal to 3001 or something else? Let's see this with the help of program. Now here, we have incremented p and after incrementation, we are going to print this value of p, value of p 6356744, okay. So, right now it is containing the address of i. After incrementation, value of p is 6356748. So, it has been incremented by 4 bytes. Why this has happened? It has not been incremented by 1 byte. Whenever a pointer is incremented, it points to the immediately next location of its type. So, p is an integer pointer. Integer requires 4 bytes of memory. So, p is holding the address of first byte of an integer. So, 6356744, this is an address of a first byte of 1 integer. So, from 445647, these many bytes, 4 bytes will be used for 1 integer. That is why whenever p is getting incremented, it points to the next integer variable. So, it has become 48. Therefore, when p has been incremented, it has been incremented actually by 4 bytes that is the size of an integer. Had it been a double pointer, p++ would then add 8 bytes to the current value stored in p. As the pointer can be incremented, it can be decremented as well. So, here we can see p-minus, after decrement, we are going to display the value of p. Let us see what value will be stored inside p now. So, after decrement, 4 bytes are decremented from the current address which is stored inside p. So it has come to the original value 6356744. So here we conclude that pointer increment and decrement operation is not same as that of simple integer variable in which one is added or one is subtracted from the current value. Now, let us see another program in which a constant value will be added that is some integer value will be added to a pointer and subtracted from the pointer. Again, p is storing the address of i, now we are printing the value inside p. Then in this expression, we are writing p is equal to p plus 3, means 3 is added in the pointer. So, after addition, we are printing the value of p, similarly after that we are doing p is equal to p-3, 3 will be subtracted from the current value of p and then we are trying to print the value of p. Let us run this program, value of p is 6356744 after addition, value of p has become 6356756. As we have seen whenever a pointer is incremented, it points to immediately next location. Now 3 has been added, so it will move 3 locations ahead. Now 3 locations ahead for the integer means 3 multiplied by the size of an integer, that is 3 multiplied by 4 is equal to 12 bytes. So here 12 bytes are added in the existing value of p. So 6356744 plus 12 will give you 6356756. In this way, 12 bytes are added when we are adding 3 to the value of p. Similarly, when we are subtracting 3 from the current value of p, now it has come to an original value because 12 bytes have been subtracted from it. In this way, we have seen all arithmetic operations related to pointer. So to conclude, we can assign one pointer variable to another pointer variable provided it is of the same type. We can apply relational operators equal to equal to greater than or less than to the pointer variables. Pointer variables can be incremented as well as decremented. Similarly, constant value can be added or subtracted from a pointer. These are references. Thank you.