How to find the size of an integer without using the sizeof operator

Showing Answers 1 - 2 of 2 Answers

praveenp16

  • May 20th, 2007
 

#define SIZEOF(X) ( (char *) (X+1) - (char *) (X) )


main()
{
int *x;
double *y;
printf("The Size of integer is %d bytesn", SIZEOF(x));
printf("The Size of double is %d bytesn", SIZEOF(y));
}

Here is another method:

int *x=0;
printf("%dn",x);
x=x+1;// The difference in these 2 values is 4. When a pointer is incremented. It is increased by size of the data type it ispointing to
printf("%dn",x);
printf("Size of Integer is %d n",sizeof(int)); // To confirm the answer

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions