Bodhak advanced pointers c tutorial in this chapter we will discuss in details about Memory Models, Working with various types of pointers, near pointer, far pointer, huge pointer, void pointer, constant pointer, pointer constant, dangling pointer, pointer to pointer.
As we are in discussions of memory and its address and the sizes, in the earlier implementation we had considered that each variable occupies the specific size of memory in the form of a bit with respect to data types.
advanced pointers c tutorial
But nowhere we had proved practically. We can check the memory size occupied by each data type by using sizeof() operator.
A near pointer is one where only the offset is used – it can only address the current segment.
The pointer which can points only 64KB data segment or segment number 8 is known as near pointer.
Near pointer is 16 bits wide and holds only offset address. This can point up to 64kb or 0xFFFF offset in a given segment.
A far pointer has both components, so can address any of the addressable 32-bit space. However, you can see that the same pointer can be expressed in different ways, depending on where you draw segment boundaries.
The pointer which can point or access whole the residence memory of RAM i.e. which can access all 16 segments is known as far pointer
A huge pointer is a far pointer that has had as much as possible expressed in the segment.
The pointer which can point or access whole the residence memory of RAM i.e. which can access all the 16 segments is known as a huge pointer.
A void pointer is a pointer which has no specified data type. The keyword ‘void’ is preceded the pointer variable because the data type is not specific. It is also known as a generic pointer. The void pointer can be pointed to any type. If needed, the type can be cast
These type of pointers are the one which cannot change the address they are pointing to. This means that suppose there is a pointer which points to a variable (or stores the address of that variable). Now if we try to point the pointer to some other variable (or try to make the pointer store address of some other variable), then pointers constant are incapable of this.
A pointer constant is declared as: ‘int *const ptr’ ( the location of ‘const’ make the pointer ‘ptr’ as constant pointer)