Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

QUICK QUESTION, ACT NOW

Name: OMGS HELP NOW!!! 2008-05-21 16:17

If I typecast a pointer to a different kind of pointer, and incrementz the pointer, will the pointer be incremented by the amount accordiing to the typecast or the real pointer?

Example:

[b]long[/b]* ptr;

([b]char[/b]*) ++ptr;


Which is the result?
A) ptr is increased by sizeof(long)  (ie. 4)
B) ptr is increased by sizeof(char)  (ie. 1)

thx in advance, kindly /prog/ warriors

Name: Anonymous 2008-05-21 16:21

Since the cast to char* is applied to the result of ++ptr, then the increment is performed before the cast, and ptr is increased by sizeof(long).

If you did:
char* q = (char*)ptr;
q++;


q would increase by sizeof(char).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List