Size of a Pointer based on datatype

There is a lot of confusion about the size of the pointers based on datatypes. A usual question is if there is a difference of size in:

int *p;
char *p;
string *p;

The answer is simple. As we discussed in the previous detailed post on pointers, A Pointer points to the address of a memory location. So, the data type declared is actually of the content stored at that address. Therefore, datatype has nothing to do with the size of pointers.

So, we can easily understand that the size of pointer is 32-bit or 64-bit based on the machine as the pointer points to a certain address of memory. Same goes for void pointers.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started