fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void copia(int *vet, int tam, int *retorno) {
  5. for(int i = 0; i < tam; i++)
  6. retorno[i] = vet[i];
  7. }
  8.  
  9. int main(void) {
  10. int tam = 3;
  11. int *vet = malloc(tam * sizeof(int));
  12. int *novo = malloc(tam * sizeof(int));
  13. vet[0] = 1;
  14. vet[1] = 2;
  15. vet[2] = 3;
  16. copia(vet, tam, novo);
  17. printf("0 -> %d\n", novo[0]);
  18. printf("1 -> %d\n", novo[1]);
  19. printf("2 -> %d\n", novo[2]);
  20. free(novo);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2288KB
stdin
Standard input is empty
stdout
0 -> 1
1 -> 2
2 -> 3