 Hello everyone, I am Mrs. Savita Palival. In this session, I am going to introduce you with the pointers in C. If I ask you a question, which feature of C language that beginners find most difficult to understand? The answer will be pointers. Really, it is hard to see how a variable can point to something. Let's see the learning outcomes of this session. At the end of this session, learners will be able to explain what is pointers in C, declare a pointer and access memory location using pointer. But before moving towards pointer, let us understand the role of computer memory during declaration of simple variable. For example, integer x is equal to 50. What does this declaration mean? It means this declaration tells compiler to reserve the space in memory to hold the integer value. Give name x to this memory location and store value 50 inside this location. So here x is a location name, 50 is a value stored inside it and 1003 is the address of that location. Now x is a data in a program. Now there is a question, where this data is stored? Data is stored in a random access memory, which is a primary memory. RAM is a collection of memory location known as cells, and every cell is of one byte. Now you can see here how memory cells look like. Each location of memory has some specific address. Different types of data in a program require different amount of memory. For example, on 32-bit processor, character data type requires one byte. Integer requires four bytes. Float requires four bytes in this way. Now here x is an integer data. It requires two bytes of space on 16-bit processor and four bytes of space in a 32-bit processor. So here you can see 1003 is the address of memory location that has been selected by computer for storing the value of x. This address is not a fixed address because computer may choose some other address for some other time. Now to print the value of x, we can write printf value of x is %dx. We know %d is a format specifier for integer. Similarly, we can print address of x. We have been using ampersand operator in a scanup statement. Similarly, we can use it in printf. Address of x is %u ampersand x as memory address is an unsigned integer. The format specifier for unsigned integer is used here that is %u. So to print the address of x, we are using %u format specifier. Now this ampersand is an address of operator. So the expression ampersand x returns the address of x. So it is going to print 1003. Now to understand pointers in C, we must get acquainted with another operator that is star. When we do arithmetic in a program star is a multiplication operator but it has other meaning too according to contest. It stands for value at address operator. This is also called as indirection operator. Now if I write star p, it means value at address stored in a p. So p is capable of storing memory address. This means p is not an ordinary variable like x. So it cannot be declared like a simple variable. Let's see the declaration. Ind star p. Here p is a name of variable not star p. Star p is not a name, p is a name of a variable. Star is used to indicate that p is a special type of variable that is a pointer variable. So this is going to tell compiler that p will be used to store the address of an integer variable. In other words, we also say that p points to an integer. Now to justify it with the value at address operator, star operator. I will once again tell you the meaning of this declaration. Let's see here. Ind star p means p contains some address 6004 and value at this address is an integer value. Value at 6004 is a 100. Again that integer value has some name. Let's say I. So I is a name given to a location which stores 100. So I is an integer variable and p is an integer pointer variable. Now let's see C language instructions. We have declared integer variable I and assigned value 100. Then we have declared a pointer variable which is of type integer n star p. Inside this pointer variable p we are storing address of I. You can see here the datatype of I is an integer. But what is datatype of p? Is it integer? As we have written n star p, no. Its datatype is an unsigned integer as it is storing the address. Unsigned integer also occupies 4 bytes of memory on 32-bit processor. If I want to print the value of I, I will simply write a printup statement. Value of I is equal to percent d I, percent d format specifier for integer and value of I that is 100 it is going to print. Then if I want to print address of I, I will use ampersand operator that is address of operator and format specifier that I am going to use is percent u because we are going to print here the memory address which is an unsigned integer. So percent u address of I is 6004 it will give you output 6004. Once again if I want to print address of I, I can print it with the help of p simply p that is value of p. Value which is stored inside p is 6004. Again percent u because it is an address. Now suppose if I want to print address of p, p address of p is 3570. So I will simply use ampersand before p, percent u ampersand p. So address of p that is 3570. So whenever we want to print address we are going to use percent u. Now let's see here if I want to print the value of I with the help of p that is with the help of a pointer variable. As it is an integer value I will use format specifier percent d then star p means value at p means value at 6004 that is at the address 6004 100 is present. So it will print 100. Let's see one more interesting statement here. Here I am going to print percent d star ampersand I. We will begin with the bracket. Inside bracket ampersand I means address of I. What is address of I? 6004. Now apply star to this 6004 that is value at 6004 again it is a 100. So this is also going to print you 100. In this way we can use pointers in different ways. Now look at these declarations integer star a, character star b, float star c. These are different pointers holding addresses of different data type variables. For example a is capable of holding address of an integer, b is capable of holding address of a character variable. Similarly c is capable of holding address of a float variable. Now here x, y and z these are some variables which are integer character and float variables respectively to whom some values are assigned. Now one thing is very clear here. We cannot make a float pointer to hold the address of a character, y is a character, c is a float pointer. So here we are attempting to assign address of character to a float pointer variable which is not possible. Similarly we cannot make a character pointer to hold address of an integer, x is an integer, b is a character pointer. So b is equal to m percent x this also we cannot do. Means every pointer variable can save the address of similar data type variable. Now one more thing is very interesting here. Think for a while and give me answer. What are the data types of these pointer variables a, b and c? Are they same or different? Now you can see here a, b and c. What are their data types? Are they same or different and what are their sizes in bytes? So we want to know what are the sizes of these pointer variables a, b and c? How much memory space they occupy? These pointer declarations look different because they are capable of storing addresses of different data type variables but all these pointer variables are holding memory addresses and memory addresses are unsigned integers. Therefore all are of same data type that is unsigned integers but their purpose is different. One can hold the address of integer, another can hold address of a character. So every pointer variable has a different purpose but every pointer variable's data type is same because everyone is holding the memory address. So this is the answer. There data types are same that is unsigned integer and size of every pointer will be 4 bytes. It will occupy 4 bytes of memory. These are the references. Thank you.