Created
November 18, 2014 02:46
-
-
Save zhangyuchi/c46fd35b69b50ce63b4b to your computer and use it in GitHub Desktop.
pointer and array in struct
This file contains hidden or 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 <stdio.h> | |
struct str{ | |
int len; | |
char s[0]; | |
}; | |
struct foo { | |
struct str *a; | |
}; | |
int main(int argc, char** argv) { | |
struct foo f={0}; | |
if (f.a->s) { //won't crash | |
printf( f.a->s); //will crash | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment