Maneesha K K
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
•An element of the program.
•A storage location.
•Its lifetime ends when the program
•Every variable has both datatype & variable
Datatype --Represents the type
Variable name --The usual way to reference the
Scope of a Variable
• A region of the program where a defined variable
can have its existence and beyond that variable can
not be accessed.
•It is the block of code where the variable is valid for
•It refers to the visibility of variable.
Type of Variable Declaration :
• Usually declared before main()& outside of all functions
used within the program.
• A variable with multiple scopes.(ie. it can be accessed
by any function).
• They remains in the memory as long as the program is
• They do not get recreated if the function is recalled.
int num1 = 1; // Global variable
int num1 = 6 ;//local variable
printf("%dn",num1); // Local variable is accessed
printf("n%d",num1); // Global variable is accessed
• Declared inside a function or Block.
• They are unknown to other functions.
• They are recreated each time a function is executed or
• They can be used only by statements that are inside that
function or block of code.
• Scope restricted by an opening brace and end
with the closing brace.
//Sample program to demonstrate local variable
int main ()
int_num3=int_num1+int_num2; //calculates the sum
printf ("value of No.1 = %dnt No.2 = %dnt No.3 =
//display the three no.s
Local Variable Vs Global Variable
• Local variables allows to focus attention on smaller
more manageable pieces of the program.
Global variable focus to keep track of how they're being
used throughout the entire system.
• While working with other people, you must coordinate
who's creating which global variables. It is not valid to
create two global variables of the same name.
• Localizing the effects of algorithm steps makes the program
easier for others to understand.
Difference b/w Global & Local Variable
int int_num1=10;//global variable
int int_num1=20;//variable declaration
int int_num2=f1();//function call
printf("t%dnt%d",int_num1,int_num2); //using local variable
x=int_num1; //using global variable
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
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.
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
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Ph: + 91 – 495 40 25 550
Hilite Business Park,
Start up Village