|
|
Tutorials

Cpp

|
Topic |
How Global variables are used in C++?
|
|
Explanation |
|
Variables that are declared outside the scope of a function, so that it can be used anywhere in the program is known
as Global Variables.
Example:
#include <iostream.h>
float pi = 3.14;
int main( )
{
int area,rad;
rad = 100;
area = pi*rad*rad;
cout << "Area of a Circle:" << area << '\n';
return 0;
}
|
Result:
Area of a Circle: 31400
In the above example "pi" is declared as global variable outside any function. But the "pi" value is
used inside the main function.
|
| Note |
C++ is one of the most used programming languages in the world. Also known as "C with Classes".
Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.
|
|
|
|