Saturday, 15 June 2013

Need help understanding pointers in given code -



Need help understanding pointers in given code -

fbyte *d = (fbyte*) dst; const fbyte *s = (const fbyte*) src; while(cnt >= sizeof(int)) { *(int*) d = *(int*) s; d += sizeof(int); s += sizeof(int); cnt -= sizeof(int); }

i new c programming , unable understand how 4th line of code working

*(int*) d = *(int*) s;

any help appreciated.

this whole piece of code copying buffer in src dst. while loop iterates on src, , in each iteration copies single int.

let's examine right hand side of 4th line:

s pointer area of source memory want copy. the first cast ((int *)s) means treating pointer int the deference before (* (int *)s) means take value point pointing to.

the same applies left hand side of expression.

so, basically, you're iterating on src buffer, , in each iteration copying value of current int dst.

pointers

No comments:

Post a Comment