What are Global Variable in C++

Global variables could be access to the whole program for every function and class. Global variable should only declare when they are too much necessary because these are accessible to the all program so there is a chance that anyone can change them.

Source Code

#include<iostream>
using namespace std;
int sum;
int main ()
{
 int num1 = 0;
 int num2 = 0;
 cout<<" Enter Your Number : ";
 cin>>num1;
 cout<<endl;
 cout<<" Enter Your Number : ";
 cin>>num2;
 sum = num1+num2;
 cout<<endl;
 cout<<" The Sum of Both Numbers is : " <<sum;
 cout<<endl;
}

Output of the Program

Global Variable in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment