3. 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. Scope of variable
•Refers to where variables can be referenced
•There are three places where variables can be declared in c
programming language
1. Local variable
2. Global variable
3. Formal parameters
5. Local variable
• Variables that are declared inside a function or block
are called local variables.
• They can be used only by statements that are inside
that function or block of code.
function_1()
{
data_type a;
}
7. Global variable
• Global variables in c have their declaration outside
the function definition of all functions used within the
program.
• They remains in the memory as long as the program
is executing.
9. Nested scope
• Local variables of same name can be nested inside global
variables.
int total = 5;
int main ( )
{
int total = 4;
….
}
int sub1 ( ) {
int i = total;
}
Nested scope
10. • Example
#include<stdio.h>
int f1();
int a=10;
main()
{
int a=20;
int b=f1();
printf(“%dn % d”, a , b);
}
f1(int x)
{
x=a;
return x;
}
Using local variable ‘a’
Using global variable ‘a’
Output
20
10
11. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
12. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
13. 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
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us