Understanding Variable Scopes
Taak
Swipe to start coding
Let's put the analogy with the library discussed in the last chapter into practice:
- Write down the content of the library book in your home notebook.
- Read the content of the library book using your home notebook.
Oplossing
solution.cpp
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;
}
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 5
single
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;
}
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.