Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Passing Structs to Functions | Struct Fundamentals
C++ Structures and Enumerations

bookChallenge: Passing Structs to Functions

When you pass a struct by reference to a function, any changes made inside the function affect the original struct, allowing you to modify its data directly. This is especially useful for updating specific fields, such as changing the age of a Person struct.

Завдання

Swipe to start coding

Complete the function so that it updates the age of a Person struct passed by reference.

  • Set the age member of the given Person to the value provided in the newAge parameter.
  • After calling updateAge, print the updated age using the template string: "Updated age: {age}".

Рішення

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Passing Structs to Functions

Свайпніть щоб показати меню

When you pass a struct by reference to a function, any changes made inside the function affect the original struct, allowing you to modify its data directly. This is especially useful for updating specific fields, such as changing the age of a Person struct.

Завдання

Swipe to start coding

Complete the function so that it updates the age of a Person struct passed by reference.

  • Set the age member of the given Person to the value provided in the newAge parameter.
  • After calling updateAge, print the updated age using the template string: "Updated age: {age}".

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
single

single

some-alt