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

book
Understanding Variable Scopes

Tarefa

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.

Solução

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;
}

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 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;
}
toggle bottom row
some-alt