Struct Pointers

Lab C Intermediate 20 points

Write void birthday(Person *p) that increases the age using p->age. Read a person and a number of birthdays, apply them, and print name is age.

Input

Line 1: name age. Line 2: birthdays.

Output

One line.

Example

Input

ann 30
3

Output

ann is 33
Sample input available Sample output available
Editor
C

Hints

p->age is shorthand for (*p).age.

Solution explanation

Passing a pointer to a struct lets the function modify it and avoids copying the whole struct.

Show solution
#include <stdio.h>

typedef struct {
    char name[30];
    int age;
} Person;

void birthday(Person *p) {
    p->age++;
}

int main() {
    Person p;
    int times;
    scanf("%s %d %d", p.name, &p.age, &times);
    for (int i = 0; i < times; i++) birthday(&p);
    printf("%s is %d\n", p.name, p.age);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD