size of pointer in c

Previous
Next

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:

CompilerInt sizePointer size
16 bit2 bytes2 bytes
32 bit4 bytes4 bytes
64 bit8 bytes8 byte

Previous
Next

Add Comment

Courses Enquiry Form