fork download
  1. #include <cstdio>
  2. #include <cstdlib>
  3.  
  4. struct S {
  5. int val;
  6. };
  7.  
  8. int main() {
  9. S* s = (S*)malloc(4*sizeof(S));
  10. s[0].val = 10;
  11. s[1].val = 20;
  12. s[2].val = 30;
  13. s[3].val = 40;
  14. for ( int i = 0; i < 4; ++i ) printf("s[%d]=%d\n", i, s[i].val );
  15.  
  16. printf("\n");
  17. S* ns = &s[1];
  18. ns->val = 100;
  19. // same print
  20. for ( int i = 0; i < 4; ++i ) printf("s[%d]=%d\n", i, s[i].val );
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
s[0]=10
s[1]=20
s[2]=30
s[3]=40

s[0]=10
s[1]=100
s[2]=30
s[3]=40