Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Scope of variables
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
4. WHAT IS A VARIABLE?
• A variable is the name for a place in the computer’s memory
where some data are stored
• Every varibale has a name called variable name and a data type
E.g. int a
int- data type
a- variable name
5. Local Variables
• Variables that are declared inside a function or block are local variables.
They can be used only by statements that are inside that function or block
of code
6. Global variables
• A global variable is a variable which is accessible in multiple scopes.
It is important to note that global variables are only accessible after they
have been declared.
• Global ariables that are defined outside of all the functions, usually on top
of the program. The global variables will hold their value throughout the
lifetime of your program.
• A global variable can be accessed by any function.
• i.e. a global variable is available for use throughout your entire program
after its declaration.
7. • // Difference between Global and Local Variables
#include <iostream>
namespace std;
int result; // Global variable declaration
int main ()
{
int a, b; // Local variable declaration
a = 10 , b = 20 ; // initialization
result = a + b;
cout << result; // Print result
return 0;
}
8. SCOPE
• The scope of a variable is the block of code where
the variable is valid for use
• If declaration is made outside the bodies of all functions and
outside the main program is called global variable
• A local declaration is one that is made inside the body of a function
• It is possible to declare the same identifier name in different parts
of the program
9. • Undisciplined use of global variables may lead to confusion and debugging
difficulties
• Instead of using global variables in functions, try passing local
variables by reference
• The use of global variable is not encouraged due to the lack of protection
of data
10. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
11. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com