fork download
  1. #include <stdio.h>
  2.  
  3. struct Data {
  4. int a[5];
  5. };
  6.  
  7. void array(struct Data *data);
  8.  
  9. int main(void) {
  10. struct Data data = {0, 1, 2, 3, 4};
  11. array(&data); // Use & to pass the address of 'data'
  12.  
  13. for (int i = 0; i < 5; i++) {
  14. printf("%d ", data.a[i]);
  15. }
  16. return 0;
  17. }
  18.  
  19. void array(struct Data *data) {
  20. data->a[1] += 1; // Use '->' to access the array within the struct
  21. }
  22.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
0 2 2 3 4