fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct test {
  6. void *ptr;
  7. char str[300];
  8. };
  9. struct test2 {
  10. int i;
  11. char astr[200];
  12. };
  13.  
  14. int main(void)
  15. {
  16. struct test *p;
  17. p = malloc(sizeof(struct test));
  18. p->ptr = malloc(sizeof(struct test2));
  19. strcpy(((struct test2 *)(p->ptr))->astr, "hello world");
  20. printf("%s\n", ((struct test2 *)(p->ptr))->astr);
  21. return 0;
  22. }
Success #stdin #stdout 0s 2380KB
stdin
Standard input is empty
stdout
hello world