finding size of variable without using sizeof()This tip submitted by Rajesh punia on 2006-11-21 00:30:19. It has been viewed 6114 times.
Rating of 3.8 with 43 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; p1=(char*)a; p2=(char*)b; p1-p2
Help your fellow programmers! Add a tip!