-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlab14functs.c
executable file
·61 lines (42 loc) · 1.45 KB
/
lab14functs.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
/** lab14functs.c
* ===========================================================
* Name:
* Section:
* Project: Lab 14
* Purpose: Introduction to Pointers
* ===========================================================
*/
#include <stdio.h>
#include "lab14functs.h"
/** ----------------------------------------------------------
* @param x first value
* @param y second value
* @pre none
* @post
*/
void swapPassByValue(int x, int y) {
printf("----- Running swapPassByValue -----\n");
printf("before swap: x = %d; y = %d\n", x, y);
// Creates a temporary value
int temp;
// Set temp to have the same value as x
// Make x have the same value as y
// Make y have the same value as temp
printf("after swap: x = %d y = %d\n", x, y);
}
/** ----------------------------------------------------------
* @param ptrX a pointer to the first value
* @param ptrY a pointer to the second value
* @pre none
* @post
*/
void swapPassByReference(int* ptrX, int* ptrY) {
printf("----- Running swapPassByReference -----\n");
printf("before swap: ptrX = %d; ptrY = %d\n", *ptrX, *ptrY);
// Creates a temporary int variable
int temp;
// Set temp to contain the value stored at ptrX
// Set the value stored at ptrX to contain the value stored at ptrY
// Set the value stored at ptrY to contain the value stored in temp
printf("after swap: ptrX = %d; ptrY = %d\n", *ptrX, *ptrY);
}