158k views
5 votes
_________ variables are defined outside all functions and are accessible to any function

within their scope.

1 Answer

2 votes

Answer:

Global Variables

Step-by-step explanation:

A Global variable is a variable defined usually in the header that can be accessed by any part in a program.

However, this is not a good practice because anything in the program can modify the value of the variable; also, helps to get more difficult to read a code, due to the fact that you need to know where are those variables and where they have been modified.

Example en c++: Check that the final result its 10, it is not necessary to pass the variable as a parameter in functions

#include <iostream>

int varGlobal = 5; // this is the global variable

void ChangeVarGlobal()

{

varglobal=10; // reference to the variable

}

void main()

{

std::cout << global << '\\'; // reference to a variable in a second function

ChangeVarGlobal();

std::cout << global << '\\';

return 0;

}

User Nikolina
by
8.0k points

No related questions found