|
|
|||||
|
Get the Ebook
C Tutorial
Source Code
Function Reference
|
Pointer arithmetic hackThis tip submitted by Vivek Ahlawat on 2005-03-07 02:09:20. It has been viewed 33200 times.Rating of 6.3 with 108 votes Here's a way to find the size of a struct without using the sizeof operator that also demonstrates how pointer arithmetic works.
struct point
{
int x ;
int y ;
}
struct point pt={0 , 0 };
point *ppt= &pt;
unsigned char *p1,*p2;
p1= (unsigned char*)ppt;
p2= (unsigned char*)++ppt;
printf("%d",p2-p1);
More tips Help your fellow programmers! Add a tip!
Want to become a C++ programmer? The Cprogramming.com ebook, Jumping into C++, will walk you through it, step-by-step. Get Jumping into C++ today!
Popular pages
Custom Search
|
||||