Created
August 25, 2014 10:50
-
-
Save rayyee/69bbc0ab4af08d93aa9a to your computer and use it in GitHub Desktop.
*&p 形参的一种表现
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstddef> | |
const char *advanceP(const char *&p, size_t n) | |
{ | |
const char *pp = p; | |
p += n; | |
return pp; | |
} | |
typedef struct | |
{ | |
int a; | |
float b; | |
char c[10]; | |
} Obj; | |
int main() | |
{ | |
const char *p; | |
const char *oldp = advanceP(p, sizeof(Obj)); | |
const Obj *objp = (const Obj*)p; | |
const Obj *objoldp = (const Obj*)oldp; | |
printf("%f\n", objp->b); | |
printf("%d\n", (*(const Obj*)oldp).a); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment