This example shows that the size of a pointer is independent of its type. All pointers store memory addresses, so their size depends on the system’s address width, not on the data type they point to.
main.c
Copy to clipboard
#include <stdio.h>
int main()
{
char *cptr;
int *iptr;
if (sizeof(cptr) == sizeof(iptr))
{
printf("Size of all pointers are equal\n");
}
else
{
printf("No, they are not equal\n");
}
if (sizeof(char *) == sizeof(long long *))
{
printf("Size of all pointers are equal\n");
}
else
{
printf("No, they are not equal\n");
}
return 0;
}
Output:
Size of all pointers are equal
Size of all pointers are equal
All pointers store addresses, so their size depends on the system architecture.
On a 32-bit system, pointer size is typically 4 bytes.
On a 64-bit system, pointer size is typically 8 bytes.
The type of the pointer (char *, int *, long long *) does not change the size of the pointer itself.
Pointer types are used to interpret the data during dereferencing, not to determine the size of the pointer.