C program to define, modify and access a global variable
In this c program we are going to tell you how to declare, define, modify and access a global variable inside main and other functions?
A global function can be accessed and modified anywhere including main() and other user defined functions.
In this program we are declaring a global variable x which is an integer type, initially we are assigning the variable with the value 100.
Value will be printed into main() then we are modifying the value of x with 200, printing the value and again modifying the value of x with 300 through the function modify_x() and printing the final value.
Here modify_x() is a user defined function that will modify the value of x (global variable), this function will take an integer argument and assign the value into x.
C program - Define, Modify and Access a Global Variable
Let's consider the following example:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer