Upcoming SlideShare
×

# Scope of variable

245 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
245
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Scope of variable

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 23 2 3 Typing Speed
3. 3. Jobs Applied Week Company Designation Applied Date Current Status 1 2 3
4. 4. WELCOME
6. 6. Overview  Variable  Scope Of Variable  Global Variable  Local Variable  Program
7. 7. Variable • Element of the Programing Language. • Hold data temporary. • Value Lost as soon as program terminate • Declaration: data type variable name;
8. 8. Scope of Variables • Scope refers to the visibility of variables. • Two types Local Global
9. 9. Global Variables • Declared out side of all Function. • Every part of program can access. • Many functions use the same data.
10. 10. Example • Example: #include <stdio.h> int count; /* count is global */ void func1(void); void func2(void); main(void) { count = 100; func1(); }
11. 11. void func1(void) { printf("count is %d", count); } void func2(void) { for(count=0; count<10; count++) printf("count is %d", count); } Example contd..
12. 12. Local Variables • Declared inside a function or Block. • Scope restricted. • Scope begun by an opening brace and ends with its closing brace.
13. 13. Example #include <stdio.h> void func1(void); void func2(void); main() { int count; /* count is global */ count = 100; func1(); }
14. 14. Example cont. void func1(void) { Int count; printf("count is %d", count); } void func2(void) { for(count=0; count<10; count++) //error printf("count is %d", count); }
15. 15. Example combination int g = 20; funcn() { Int g=30; //print 30 Printf(“%d”,g); } int main () { Printf(“%d”,g); //print 20 }
16. 16. Factorial Of a Number #include<stdio.h> int Factorial(int n) { int fact=1; if(n==1) return 1; else return fact=n*Factorial(n-1); }
17. 17. Factorial contd.. main() { int n,f; printf("enter Number to find factorial: "); scanf("%d",&n); f=Factorial(n); printf("factorial of %d: %d",n,f); }
18. 18. Return 3*2 i.e 6 • N=5 • 5*Factorial(4); • 4*Factorial(3); • 3*Factorial(2); • 2*Factorial(1); • Return 1 Return 4*6 i.e 24 Return 2*1 i.e 2 Return 5*24 i.e 120 Factorial of 5 :120
19. 19. Thank you