1.

Explain scope rules of functions and variables in a C++ program

Answer»

1. Local variable or function: 

A variable or function declared inside a function is called local variable or function. This cannot be accessed by the outside of the function.

Eg. 

main() 

{

int k;//local variable ,

cout<<sum(a,b); // local function

}

2. Global variable or function: 

A variable or function declared out side of a function is called global variable or function. This can be accessed by any statements. 

Eg

int k; // global variable 

int sum(inta, int b); //global function

main()

}



Discussion

No Comment Found