Size of Pointer:
- Primitive Variables store different types of data which are of different sizes.
- We can find the size of type using sizeof() function.
#include<stdio.h>
int main()
{
char a;
short b;
float c;
double d;
printf("char size : %d \n", sizeof(a));
printf("short size : %d \n", sizeof(b));
printf("float size : %d \n", sizeof(c));
printf("double size : %d \n", sizeof(d));
return 0;
}
- Pointer variable holds an address.
- Address is of integer type.
- Every pointer variable size is equals to integer size.
#include<stdio.h>
int main()
{
char* a;
short* b;
float* c;
double* d;
printf("char* size : %d \n", sizeof(a));
printf("short* size : %d \n", sizeof(b));
printf("float* size : %d \n", sizeof(c));
printf("double* size : %d \n", sizeof(d));
return 0;
}
Pointer size varies from compiler to compiler:
| Compiler | Int size | Pointer size |
| 16 bit | 2 bytes | 2 bytes |
| 32 bit | 4 bytes | 4 bytes |
| 64 bit | 8 bytes | 8 byte |