#c How to set global variables?
1. First, define a custom function that implements addition operation.
#2. Next, define a custom function that implements multiplication.
#3. Finally, implement the program operations in the main function.
#4. Variables defined outside a function that are not enclosed in curly braces are called global variables. The scope of a global variable starts from the location where the variable is defined and ends at the end of the file.
#5. If multiple functions in a program have to process the same variable, you can define this variable as a global variable, such as the custom function in this example Both product and main function use global variables.
#6. Run the program and you can see that global variables have an effect on any function located behind the global variable definition in the file.
Recommended learning: c Video tutorial
The above is the detailed content of How to set global variables in c++. For more information, please follow other related articles on the PHP Chinese website!