-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpass_by_reference.c
More file actions
44 lines (32 loc) · 900 Bytes
/
Copy pathpass_by_reference.c
File metadata and controls
44 lines (32 loc) · 900 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
41
42
43
#include <stdio.h>
// why does the pass by reference not return anything?
void add(int *a, int *b, int *sum){ // formal parameters
printf("number 1 in the add function scope is %d\n", *a);
printf("number 2 in the add function scope is %d\n", *b);
*sum = *a + *b;
// doesnt return anything
}
int main(){
// dito natin idedefine yung numbers to be added
int a = 2;
int b = 5;
// address_of_operator
int* a_ptr = &a;
int* b_ptr = &b;
int sum;
int *sum_ptr = ∑
add(&a, &b, &sum);
printf("the sum is %d\n", sum);
}
// dereferencing
// indirection
// int value_of_a = *a_ptr;
// int value_of_b = *b_ptr;
// printf("number 1 is %d\n", value_of_a);
// printf("number 2 is %d\n", value_of_b);
//
// int ∑ - invalid
// these are the same:
// int* sum;
// int * sum;
// int *sum;