Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara 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.

Compito

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

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

close

Awesome!

Completion rate improved to 8.33

bookChallenge: Passing Structs to Functions

Scorri per mostrare il 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.

Compito

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

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
single

single

some-alt