-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathage-edit-call-by-ref.c
35 lines (29 loc) · 1.01 KB
/
age-edit-call-by-ref.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
# include<stdio.h>
void edit(int *);
void main()
{
char resp;
int age = 25;
int prev_age = age;
printf("Do you want to change your age from %d?\n", age);
printf("Press 'Y' to change and 'N' to ignore: ");
scanf("%c", &resp);
if (resp == 'Y')
{
edit(&age);
printf("Your age has been changed from %d to %d.", prev_age, age);
}
else
printf("You chose not to change your age.");
}
void edit(int *n_age)
{
printf("Enter your new age: ");
scanf("%d", n_age);
}
/* Output:
Do you want to change your age from 25?
Press 'Y' to change and 'N' to ignore: Y
Enter your new age: 26
Your age has been changed from 25 to 26.
*/