summaryrefslogtreecommitdiff
path: root/main.c
blob: 83bf64da0c3d0493fca44dbf0a00f4d069539d61 (plain)
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
  int age;
  int happiness; // 0 sad, 100 happy
} Person;

void slide(Person *person)
{
  person->happiness += 10;
}

// pass by value
// pass by reference
int main(int argc, char *argv[])
{
  Person *mo = malloc(sizeof(Person));
  mo->age = 36;
  mo->happiness = 70;

  printf("Before: age(%d), happiness(%d)\n", mo->age, mo->happiness);

  slide(mo);

  printf("After: age(%d), happiness(%d)\n", mo->age, mo->happiness);
}