Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Comprendre les Portées des Variables | Introduction
Fonctions C++

book
Comprendre les Portées des Variables

Tâche

Swipe to start coding

Mettons en pratique l'analogie avec la bibliothèque discutée dans le dernier chapitre :

  • Écris le contenu du livre de la bibliothèque dans ton carnet de notes personnel.
  • Lis le contenu du livre de la bibliothèque en utilisant ton carnet de notes personnel.

Solution

cpp

solution

#include <iostream>

// Function that simulates reading the book in the library
std::string readLibraryBook() {
// Here we have a book with its content
std::string book = "Hello, user!";
return book;
}

int main()
{
// We have no access to the book because it remains in the library
// But we remember the content of the book and can write it somewhere
// Find notebook at home to write down the content
std::string notebook;

// Write down the content to your home notebook
notebook = readLibraryBook();

// Now we have the content of the book in our notebook and can use it
std::cout << "Library book content: " << notebook << std::endl;
}

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 5
#include <iostream>

// Function that simulates reading the book in the library
std::string readLibraryBook() {
// Here we have a book with its content
std::string book = "Hello, user!";
return book;
}

int main()
{
// We have no access to the book because it remains in the library
// But we remember the content of the book and can write it somewhere
// Find notebook at home to write down the content
string notebook;

// Write down the content to your home notebook
notebook = ___;

// Now we have the content of the book in our notebook and can use it
std::cout << "Library book content: " << ___ << std::endl;
}

Demandez à l'IA

expand
ChatGPT

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

some-alt