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
solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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 ?
Merci pour vos commentaires !
Section 1. Chapitre 5
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion