Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
Scope Of Variables
Sibin Raj P.R
sibinrajotk@gmail.com
8086498752
WHAT IS A VARIABLE?
• A variable is the name for a place in the computer’s memory
where some data are stored
• Every varib...
Local Variables
• Variables that are declared inside a function or block are local variables.
They can be used only by sta...
Global variables
• A global variable is a variable which is accessible in multiple scopes.
It is important to note that gl...
• // Difference between Global and Local Variables
#include <iostream>
namespace std;
int result; // Global variable decla...
SCOPE
• The scope of a variable is the block of code where
the variable is valid for use
• If declaration is made outside ...
• Undisciplined use of global variables may lead to confusion and debugging
difficulties
• Instead of using global variabl...
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.co...
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, N...
Scope of variables
Upcoming SlideShare
Loading in …5
×

Scope of variables

283 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
283
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Scope of variables

  1. 1. 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
  2. 2. Scope Of Variables Sibin Raj P.R sibinrajotk@gmail.com 8086498752
  3. 3. 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
  4. 4. 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
  5. 5. 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.
  6. 6. • // 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; }
  7. 7. 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
  8. 8. • 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
  9. 9. 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
  10. 10. 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

×