Home / Tutorial / Programming / C / C ++ Programming Tutorial (Episode 13) Pointer (2)
c programming tutorial

C / C ++ Programming Tutorial (Episode 13) Pointer (2)

In today’s C / C ++ programming tutorial phase, talk about what the pointer is and how it works. Pointer is a special type of variable, which can contain addresses of certain types of variables. Using a pointer, a programmer can work directly with the address. However, working on direct addresses is a low-level language feature. In C, there is a high-level and low-level language language, which is called mid-level language. All these programs are the sum of some data and instruction. In C, variables are usually declared to work with data.

There are many languages ​​where the variables are not used to access the data. However, regardless of the language, for every variable while running the program, (or where the data is kept) certain places are occupied in memory. Again when running a program, it is first loaded in memory. Then the processor starts working with memory as required by the instruction. So, to create a program, a programmer has to think about memory. Memory is also used efficiently when using program data in a moderate way. As a result, the speed of the program increases and runtime decreases. When discussing arrays, it is shown how to reduce the complexity of the program due to the use of arrays. It also shows how to reduce the complexity of using pointer.


Pointer is a special variable, but it can not contain any common values. It can only contain addresses of other variables. Address is the main theme for a program. Each variable has an address. The program knows those variables not by their name but by their address. If you change anything in that address, then the changes will be seen in the relevant variables. That is, the addresses that contain a variable are deleted by the value of the address, so the value of the variable will also be deleted. Again, new values ​​are assigned to an address, the value of the address that has the address will change.

Variable address

In order to work with Variables in C, the address operator is used and it is expressed with ‘&’. This operator can be used only with variables. For example, a variable will say, but it will mean that the address of the variable. Even in C, sometimes variables have to be addressed. That is why scanf (”% d ”, & x) is used inside the function when taking an input. That means here the program is told, keep inputs in the TiI address. Similarly, it is possible to print addresses of a variable.

Typically variables are usually written in the name of variables. But if you want to print an address, printf (”% d ”, & x) is written as such. Remember, the print command will not print the value of the print command, but instead its print will be printed. But the address will be printed on hexadecimal numbers. Computer usually takes the input to hexadecimal and gives output. But when the processor calculates the binary. Again, if the user wants to output the output, then it is displayed in a decimeline. The easiest way to know if a number is in hexadecimal, if the number is hexadecimal, then at the end there will be.

Pointer Variable

Though the pointer is the last type, it is still a variable. It has to be declared as a common variable. There are also different types of pointers. Remember, the common variables are the same as the pointer. For example: an integer type pointer for the integer, the character type pointer for the character, etc. The rules for deciding the pointer are similar to the common variables, but there is a little difference here
The pointer has to use the symbol. Such as:

int * gpa; A_ev int * gpa;
char * grade; A_ev char * grade;
double * cgpa; A_ev double * cgpa;

To be sure, the sign is used when declaring the pointer here. This sign means that the declarative variable is a pointer variables. It can be used in both ways. This declaration is to be done just before the name of the variable or right after the data type during the declaration. But it can show errors other than these two places. For example: Writing the first line means the pointer to an integer type of the name ‘Madhadh’ is declared, which can only contain the addresses of the variables in the type of integer type. The second line indicates that a pointer variables named Maudhphab have been declared, which can only contain the character type variables in character. There are actually two parts here.

One is the data type pointer. This means that the first part of the declaration indicates that the pointer will be able to point to any type of data type. And the next part is the name of the pointer. It can be any name like normal variables. Note that the pointer does not actually contain any data type. We know that data types of different types can hold different types of data. For example, the character type variable can contain up to 255 values. Again, integers can hold up to the highest of 32767. There is no such thing as pointers in the pointers that the pointer type of integer type is somehow, and the character type pointer may hold another value. All pointers can hold the same value. As long as the pointer to an integer type can contain the number, the pointer to the character type can contain the same number. The only difference is that for different variables, different types mean different variables will be different, and for different types of pointers, the point is to point to different types of variables.

For this reason the pointer should be called the data type pointer without the data type. In other words, when the general variable is declared in the program, the compiler is informed that the data can be placed between the variables. And when the pointer is declared in the program, the compiler is informed that the pointer can point to any type of variable. It is not here that the pointer of each type can hold the number up to one limit. Because, each cell in memory has its own address. However, the number of bits required for publishing the address of each cell in memory is equal to. That means if 10 bits are required to display the first cell address of memory, then 10 bits will be required to publish a cell address in the middle. And since the pointer contains the memory cell address, so all the pointer can hold the same number of bits.

Both common variables and pointers are the same. That is to keep the data. Keeps one data and another keeps the address. So the names of both variables and pointers between the same scope can not be the same. The rules for declaration of common variables and pointer are the complete one. So, common variables can be declared at the same time, so the pointer can also be declarated together. For example: int x, y, * z; Here the variables of three integers type are declared. The first two common variables and the third pointers are the variables. The primary function of the pointer is to hold the memory address.

But the memory address is a number. So keeping the number in the pointer means saving it to another cell in memory. Depending on the number of cells used to store pointer data, it depends on the architecture of the computer. The architecture of different types of computers is of some kind. It also depends on operating system, compiler etc. Since it is necessary to keep the data of the pointer again, it can be said that, like the common variable, the pointer also has its own address. Depending on how many bytes will be captured for this address, depending on architecture, operating system etc.

About Admin

Leave a Reply

Your email address will not be published. Required fields are marked *