Maneesha K K
maneeshakk16@gmail.com
www.facebook.com/username
twitter.com/username
in.linkedin.com/in/profilename
75598139...
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
VARIABLE
•An element of the program.
•A storage location.
•Its lifetime ends when the program
terminate.
•Every variable h...
Datatype --Represents the type
Variable name --The usual way to reference the
stored value
Eg:
int number;
Variable name
D...
Scope of a Variable
• A region of the program where a defined variable
can have its existence and beyond that variable can...
1.Global Variable
• Usually declared before main()& outside of all functions
used within the program.
• A variable with mu...
Eg:
#include<stdio.h>
void message();
int num1 = 1; // Global variable
void main()
{
int num1 = 6 ;//local variable
printf...
2.Local Variable
• Declared inside a function or Block.
• They are unknown to other functions.
• They are recreated each t...
//Sample program to demonstrate local variable
#include <stdio.h>
int main ()
{
//variable declaration
int int_num1,int_nu...
Local Variable Vs Global Variable
• Local variables allows to focus attention on smaller
more manageable pieces of the pro...
Difference b/w Global & Local Variable
#include<stdio.h>
int f1();
int int_num1=10;//global variable
main()
{
int int_num1...
Thank You……
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many con...
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ s...
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Sta...
Scope of variable
Upcoming SlideShare
Loading in …5
×

Scope of variable

524 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
524
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Scope of variable

  1. 1. Maneesha K K maneeshakk16@gmail.com www.facebook.com/username twitter.com/username in.linkedin.com/in/profilename 7559813984 SCOPE OFVARIABLE
  2. 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. 3. VARIABLE •An element of the program. •A storage location. •Its lifetime ends when the program terminate. •Every variable has both datatype & variable name.
  4. 4. Datatype --Represents the type Variable name --The usual way to reference the stored value Eg: int number; Variable name Datatype
  5. 5. 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 use. •It refers to the visibility of variable. Type of Variable Declaration : 1.Global Variable 2.Local Variable
  6. 6. 1.Global Variable • 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 executing. • They do not get recreated if the function is recalled.
  7. 7. Eg: #include<stdio.h> void message(); int num1 = 1; // Global variable void main() { int num1 = 6 ;//local variable printf("%dn",num1); // Local variable is accessed message(); } void message() { printf("n%d",num1); // Global variable is accessed }
  8. 8. 2.Local Variable • Declared inside a function or Block. • They are unknown to other functions. • They are recreated each time a function is executed or called.(recursion) • 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.
  9. 9. //Sample program to demonstrate local variable #include <stdio.h> int main () { //variable declaration int int_num1,int_num2,int_num3; //variable initialization int_num1= 10; int_num2= 20; int_num3=int_num1+int_num2; //calculates the sum printf ("value of No.1 = %dnt No.2 = %dnt No.3 = %dn",int_num1,int_num2,int_num3); //display the three no.s return 0; }
  10. 10. 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.
  11. 11. Difference b/w Global & Local Variable #include<stdio.h> int f1(); int int_num1=10;//global variable main() { int int_num1=20;//variable declaration int int_num2=f1();//function call printf("t%dnt%d",int_num1,int_num2); //using local variable } //function definition f1(int x) { x=int_num1; //using global variable return x; } Output : 20 10
  12. 12. Thank You……
  13. 13. 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.
  14. 14. 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
  15. 15. 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

×