0
What are local variables and gloabal variable
2 Answers
+ 1
Local variables are declared in a particular scope. This means they can only be accessed within the particular function, or if statement, or while loop, etc.
Here 'sum' is an example of a local variable.
int add (int a, int b) {
int sum = a + b;
return sum;
}
Global variables are declared outside all functions and statements, and can be accessed anywhere. Here 'x' is a global variable:
#include <iostream>
using namespace std;
int x = 15;
int main()
{
return 0;
}
Hope this helps :)