blog




  • Essay / The concept of a developer pointer

    Table of contentsDefinitionWhat is the purpose of developer pointersPointer and arrayPointer to structurePointer to functionsDefinitionA pointer variable is a variable that maintains the addresses of memory locations. Like other data values, memory addresses or pointer values ​​can be stored in variables of the appropriate type. A variable that stores an address is called a pointer variable, but it is often just called a plain pointer. Say no to plagiarism. Get a tailor-made essay on “Why Violent Video Games Should Not Be Banned”? Get the original essay The definition of a pointer variable, ptr, must specify the data type that ptr points to. Here is an example: int *ptr; The asterisk before the variable name indicates that ptr is a pointer variable and the int data type indicates that ptr can only be used to point to or hold integer variable addresses. This definition reads as "ptr is a pointer to int". It's also useful to think of *ptr as the "variable that ptr points to". with this point of view, the definition of ptr just given can be read as "as the variable to which ptr points is of type int". because the asterisk (*) allows you to pass from a pointer to the pointed variable, it is called the indirection operator. It is the responsibility of the programmer to keep track of the type of data stored in each memory location. The data could be a number or text (which is just a sequence of numbers, of course) or the address of another location or possibly the address of an address, etc. There are also high-level languages ​​- typed languages ​​- that work in the same way; Forth and BCPL are examples that come to mind. The majority of high-level languages ​​support data typing to a greater or lesser extent. This means, in effect, that the programmer specifies that a variable contains a specific type of data and that the language only allows appropriate operations on that variable. The advantage of using pointers is efficient in handling arrays and structures, pointers allow references to functions and help in passing functions as arguments to other functions, they also reduce the length of the program and its execution time and allow the C language to support Dynamic. Memory management. What is the purpose of developer pointers Pointer and Array I learned earlier in the previous chapter that an array name, without brackets or subscripts, actually represents the starting address of the array. This means that an array name is a pointer. Program the next page displaying a table name used with the indirection operator. Remember that the array elements are stored together in memory, as shown in the image below. It makes sense that if the numbers are the address of the numbers[0], values ​​could be added to the numbers to get the addresses of the other elements in the array. In other words, if you add one to the number, you actually add 1 * sizeof (short) to the numbers. If you add two to number , the result is number +2* sizeof (short), and so on. This conversion means that an element of an array can be retrieved by adding its index to a pointer to the array. Pointer to Pointer: Pointers are used to hold the address of other variables of similar data type. But if you want to store the address of a pointer variable, you need to store it again. So when a pointer variable stores the address of another pointer variable, it is called Pointer variable.