finding size of variable without using sizeof()

This tip submitted by Rajesh punia on 2006-11-21 00:30:19. It has been viewed 7957 times.
Rating of 3.8 with 45 votes

Here's a trick for finding the size of a variable without using sizeof--not something you'd generally do, but it demonstrates the ability to use pointer arithmetic. This trick is highly dependent on the layout your compiler uses for stack variables though!

int a,int b
char *p1,*p2;

More tips

Help your fellow programmers! Add a tip!