--- In [email protected], "titli_juit" <[EMAIL PROTECTED]> wrote:
>
> char *p="asdaddaddA";
> printf("%d",sizeof(p));
> 
> the ans is 2 or 4 depending on compiler. can u plzz expalin why it 
> would be so? i think that the sizeof operator on a pointer type 
> variable returns size of the type of object pointer points to.
>

Hi,

run this program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(void)
{
  char a[]="hello world";
  char *j="hello world";
  float *p;
  int *k;
  double *q;
  clrscr();

  printf("pointer size=%d",sizeof(k));
  printf("\npointer size=%d",sizeof(j));
  printf("\npointer size=%d",sizeof(p));
  printf("\npointer size=%d",sizeof(q));


  printf("\n\ninteger size=%d",sizeof(*k));
  printf("\nchar size=%d",sizeof(*j));
  printf("\nfloat size=%d",sizeof(*p));
  printf("\ndouble size=%d",sizeof(*q));


  getch();
}

the surprising thing is that the pointer size for all variable is the
same. While when we call "*[variable name]", sizeof basically returns
the size of the variable pointed by the pointer.

I Hope this might solve your query.

regards,
Kumail

Reply via email to