Size of pointer a

int *a= new int[n]
cout<<sizeof(a)

why it is giving 8 as in video sir told thayt it gives the size of pointer a which in this is integer so it should be 4.

Hello @tejuschaturvedi0
int *a=new int[n]
cout<<sizeof(a);

this will give you 8 because you are printing size of a pointer
you will get 4 if you print size of integer variable
int a=10;
cout<<sizeof(a); // this will give 4

int a=4;
int *b=&a;
cout<<sizeof(b);// this will also give 8 as it is pointer

char var=‘a’;
char *ptr=&var;
cout<<sizeof(ptr)<<endl; // this will also give 8 as it is also pointer

So why size of a pointer is 8 only. Does it changes with data type.

@tejuschaturvedi0 The 8 -byte count taken up by pointers is crucially exclusive to 64-bit machines, and for a reason - 8 bytes is the largest possible address size available on that architecture. Since one byte is equal to eight bits, 64 bits / 8 = 8 represents the size of a pointer .

and for 32 bit system the size of the pointer will come out to be 4 byte as 32/8=4 bytes.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like