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