Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Understanding Variable Scopes | Introduction
C++ Functions

book
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

solution.cpp

#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?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 5
single

single

#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

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

We use cookies to make your experience better!
some-alt