[2024]Digital Global Overview Report 2024 Meltwater.pdf
Scope of variable
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
3.
4. Scope of variables
Jaseena A P
jsnp65@gmail.com
www.facebook.com/Jaseena
Muhammed A P
twitter.com/username
in.linkedin.com/in/profilena
me
9539443588
5. WHAT IS A VARIABLE?
In computer programming, a variable is a storage
location and an associated symbolic
name (an identifier) which contains some known or
unknown quantity or information, a value.
The variable name is the usual way to reference the
stored value; this separation of name and content
allows the name to be used independently of the
exact information it represents.
6. WHAT IS SCOPE?
The part of a computer program where the identifier,
can be used to find the referred entity.
Scoping rules are crucial in modular programming, so a
change in one part of the program does not break an
unrelated part.
8. SCOPE (CONTD…)
In lexical scoping (or lexical scope; also called static
scoping or static scope), if a variable name's scope
is a certain function, then its scope is the program
text of the function definition.
In dynamic scoping (or dynamic scope), if a variable
name's scope is a certain function, then its scope is
the time-period during which the function is
executing.
9. LEVELS OF SCOPE
Expression scope
Block scope
Function scope
Module scope
File/Global scope
Local scope
Global scope
10. LEVELS OF SCOPE(contd…)
Expression scope: A declaration's scope is a single
expression.
eg:-int sum(int a,int b);
Block scope: scope is restricted to a block.
Eg:-char a;
switch(a)
{
case y:
//do something
case n:
//do something
}
11. LEVELS OF SCOPE(contd…)
Function scope: Scope of the variable is restricted
to the body of the function which declared it.
void sum(int a,int b)
{
int c;// c is alive inside sum() only.
}
void main()
{
int sm;//sm is alive in main() only
}
12. Module scope: In modular programming, the scope of
a name can be an entire module, however it may be
structured across various files.
Eg:- Python
Global/File scope: A declaration has global scope if it
has effect throughout an entire program. Variable
names with global scope are frequently considered bad
practice due to the possibility of name collisions.
LEVELS OF SCOPE(contd..)
13. LEVELS OF SCOPE(contd…)
Example for global(global/file scope)
variable
int year = 1994; // global variable
int Max (int, int); // global function
int main (void) // global function
{ //... }
14. Local vs Global scope
int xyz; // xyz is global
void Foo (int xyz) // xyz is local to the body
of Foo
{ if (xyz > 0)
{ double xyz; // xyz is local to this block //...
}
}
16. 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
17. 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