Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Passing Structs to Functions | Struct Fundamentals
Quizzes & Challenges
Quizzes
Challenges
/
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.

Tâche

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}".

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you show an example of passing a struct by reference?

What is the syntax for passing a struct by reference in different programming languages?

Are there any drawbacks to passing structs by reference?

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Passing Structs to Functions

Glissez pour afficher le menu

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.

Tâche

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}".

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4
single

single

some-alt