scope of variables

273 views
168 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
273
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
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. Week Target Achieved 1 30 25 2 3 Typing Speed
  3. 3. Jobs Applied Week Company Designation Applied Date Current Status 1 2 3
  4. 4. WELCOME
  5. 5. Scope of variables Midhun sudhakar midhusudhakaran@gmail.c om Midhun.sudhakar.73@face book.com twitter.com/username in.linkedin.com/in/profilen ame
  6. 6. Content • Variables • Scope • Types of scopes
  7. 7. What is a variable? • A storage location and an associated symbolic name. • Contain some quantity of info, a value. • Variable name is the usual way to reference the stored value. • Its value may change during execution.
  8. 8. What is its scope? • It refers visibility of variables. • In other words, which parts of your program can see or use it.
  9. 9. Types of scope • Global scope. • Local scope.
  10. 10. Global variables • Declared outside all functions. • Every part of your program can access.
  11. 11. example #include<stdio.h> int a, b,answer; // Global variables int main() { a = 5; b = 7; ` answer=a+b; printf("%dn",answer); }
  12. 12. Local variable • a variable that is declared inside a function. • limit a variable's scope to a single function. • changes inside the function can't affect the main program.
  13. 13. example #include<stdio.h> int main() { int a, b,answer; // locall variables a = 5; b = 7; printf("%dn",answer); }
  14. 14. example • Example program using global and local variables: #include<stdio.h> // Global variables int a; int b; int Add() { return a + b; } int main() { int answer; // Local variable a = 5; b = 7; answer = Add(); printf("%dn",answer); return 0; }
  15. 15. When trying access a local variable outside the function? • It will leads to syntax error. Example: #include<stdio.h> int Add() { return a + b; } int main() { int a,b,answer; // Local variable a = 5; b = 7; answer = Add(); printf("%dn",answer); return 0; }
  16. 16. Initializing Local and Global Variables when you define them as follows: Local variable Global variables • must be initialized by the programmer. • initialized automatically by the system. Data Type Initial Default Value int 0 char '0' float 0 double 0 pointer NULL
  17. 17. THANK YOU
  18. 18. 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
  19. 19. 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 IKK Road, East Hill, Kozhikode Kerala, India. Ph: + 91 – 495 30 63 624 NIT-TBI, NIT Campus, Kozhikode, Kerala, India.

×