![]() If p1 and p2 point to variables that are related to each other, such as elements of the same array, then p1 and p2 can be meaningfully compared. Pointers may be compared by using relational operators, such as =. When the above code is compiled and executed, it produces the following result − (* let us have array address in pointer *) This program creates an array, places the data into the array, then prints the data to the screen. The array can hold the record without violating its data type rules. The record can hold multiple data of different data types, but sill be of type record. The following program increments the variable pointer to access each succeeding element of the array −Īrr: array of integer = (10, 100, 200) The record type can get around the problem of arrays requiring the same data type. We prefer using a pointer in our program instead of an array because the variable pointer can be incremented, unlike the array name, which cannot be incremented because it is a constant pointer. The bitpacking is fully applied when using ordinal types. If ptr points to a character, whose address is 1000, then above operation will point to the location 1001 because next character will be available at 1001. IOW, if you have array elements that when bitpacked use 2 bits each and you have 3 of those elements (for a total of 6 bits), that array is going to take one entire byte because the next bitpacked field is not allowed to be part of a structured type even when packed. This operation will move the pointer to next memory location without impacting actual value at the memory location. An array can have more than one dimension, as in the following examples: type MonthTemps array 1.24, 1.31 of Integer YearTemps array 1.24, 1.31, Jan.Dec of Integer These two array types are built on the same core types. Now, after the above operation, the ptr will point to the location 1004 because each time ptr is incremented, it will point to the next integer location, which is 4 bytes next to the current location. Assuming 32-bit integers, let us perform the increment operation on the pointer − To understand pointer arithmetic, let us consider that ptr is an integer pointer, which points to the address 1000. There are four arithmetic operators that can be used on pointers: increment, decrement, +, and. Therefore, you can perform arithmetic operations on a pointer just as you can on a numeric value. ![]() As explained in main chapter, Pascal pointer is an address, which is a numerical value stored in a word. ![]()
0 Comments
Leave a Reply. |