![]() |
In C++, global variables are like normal variables but are declared outside of all functions and are accessible by all parts of the function. In this article, we will learn how to declare a global variable in C++. Global Variable in C++We can declare a global variable, by defining it outside of all functions at the top after the header files. Once the global variable is declared, it can be accessed from the scope of the Syntax to Declare Global Variable in C++A global variable is declared in the same way as any other variable but it is placed outside of every function. dataType globalVariableName = variableValue; C++ Program to Declare Global VariablesThe below example demonstrates how we can declare global variables in C++.
Output Global variable value: 10 Global variable value: 10
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |