Global Variable Assignment Help

Assignment Help: >> Functions, Arguments and Overloading - Global Variable

Global variable

Global variables are variables that defined outside the major function block. These variables are referred by the similar data type and through the similar name throughout the program  in  the  calling  portion  of  a  program  and  in  the  function  block both  . Whenever a few of the variables are treated as constants in both the main and the function block that is advisable to use global variable.

Example:

int x,y = 4;

void main(void)

{

void funct1( );

x = 10;

funct1 ( );

}

void funct1 ( )

{

int sum;

sum = x +y;

}

Sample program

//global and local variable declaration

# include<iostream.h>

int x;   //global variable

int y = 5;         //global variable

void main (void)

{

x = 10;

void sum (void);

sum ( );

}

void sum ( )

{

int sum;          //local variable

Sum = x + y;

cout<< "x = " <<x<<endl;

cout<<"y="<<y<<endl;

cout<<"sum = "<<sum << endl;

}

Output of the program

x = 10 y = 5

Sum = 15

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd