-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathlab3_task2.c
More file actions
48 lines (41 loc) · 939 Bytes
/
lab3_task2.c
File metadata and controls
48 lines (41 loc) · 939 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
44
45
46
47
48
/*
* Lab 3, Task 2
* Edasu Yadık, 231AEB028
*
* Practice using pointers as function parameters.
* Implement:
* - swap (exchange values of two ints)
* - modify_value (multiply given int by 2)
*
* Rules:
* - Use pointers to modify variables in the caller.
* - Demonstrate changes in main.
*
* Example:
* int a = 5, b = 10;
* swap(&a, &b); // now a = 10, b = 5
*
* modify_value(&a); // now a = 20
*/
#include <stdio.h>
// Function prototypes
void swap(int *x, int *y);
void modify_value(int *x);
int main(void) {
int a = 3, b = 7;
printf("Before swap: a=%d, b=%d\n", a, b);
swap(&a, &b);
printf("After swap: a=%d, b=%d\n", a, b);
modify_value(&a);
printf("After modify_value: a=%d\n", a);
return 0;
}
// Implement functions below
void swap(int *x, int *y) {
int temp = *x;
*x = *y;
*y = temp;
}
void modify_value(int *x) {
*x = *x * 2;
}