-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32_modify_array.c
More file actions
40 lines (27 loc) · 838 Bytes
/
32_modify_array.c
File metadata and controls
40 lines (27 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* Passando arrays e elementos para uma função */
#include <stdio.h>
#define SIZE 5
void modificaArr(int [], int);
void modificaElem(int);
int main() {
int arr[SIZE] = {0, 1, 2, 3, 4};
printf("arr original (referencia)\n");
for (int i = 0; i <= SIZE - 1; i++)
printf("%3d", arr[i]);
printf("\n");
modificaArr(arr, SIZE); // referencia
printf("Valores modificados:\n");
for (int i = 0; i <= SIZE - 1; i++)
printf("%3d", arr[i]);
printf("\nPassando elemento do arr por valor/copia\nO valor de arr[3] eh %d\n", arr[3]);
modificaElem(arr[3]); // copia
printf("O valor de arr[3] eh %d\n", arr[3]);
return 0;
}
void modificaArr(int arr[], int size) {
for (int i = 0; i < size; i++)
arr[i] *= 2;
}
void modificaElem(int el) {
printf("Valor modificado no escopo da funcao eh: %d\n", el *=2);
}