24

Scope of variable

Embed Size (px)

Citation preview

Page 1: Scope of variable
Page 2: Scope of variable

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

Page 3: Scope of variable

Week Target Achieved

1 30 23

2

3

Typing Speed

Page 4: Scope of variable

Jobs Applied

Week Company Designation Applied Date Current Status

1

2

3

Page 5: Scope of variable

WELCOME

Page 6: Scope of variable

Muhammed Ajmal IK [email protected] www.facebook.com/username twitter.com/username in.linkedin.com/in/profilename 9745020951

Scope Of Variable

Page 7: Scope of variable

Overview

Variable

Scope Of Variable

Global Variable

Local Variable

Program

Page 8: Scope of variable

Variable

• Element of the Programing Language.

• Hold data temporary.

• Value Lost as soon as program terminate

• Declaration:

data type variable name;

Page 9: Scope of variable

Scope of Variables

• Scope refers to the visibility of variables.

• Two types

Local

Global

Page 10: Scope of variable

Global Variables

• Declared out side of all Function.

• Every part of program can access.

• Many functions use the same data.

Page 11: Scope of variable

Example

• Example: #include <stdio.h>

int count; /* count is global */

void func1(void);

void func2(void);

main(void)

{

count = 100;

func1();

}

Page 12: Scope of variable

void func1(void)

{

printf("count is %d", count);

}

void func2(void)

{ for(count=0; count<10; count++) printf("count is %d", count); }

Example contd..

Page 13: Scope of variable

Local Variables

• Declared inside a function or Block.

• Scope restricted.

• Scope begun by an opening brace and ends with its

closing brace.

Page 14: Scope of variable

Example

#include <stdio.h>

void func1(void);

void func2(void);

main()

{

int count; /* count is global */

count = 100;

func1();

}

Page 15: Scope of variable

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);

}

Page 16: Scope of variable

Example combination

int g = 20;

funcn()

{

Int g=30; //print 30

Printf(“%d”,g);

}

int main ()

{

Printf(“%d”,g); //print 20

}

Page 17: Scope of variable

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);

}

Page 18: Scope of variable

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);

}

Page 19: Scope of variable

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

Page 20: Scope of variable

Thank you

Page 21: Scope of variable

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

Page 22: Scope of variable

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: [email protected]

IKK Road, East Hill, Kozhikode Kerala, India. Ph: + 91 – 495 30 63 624

NIT-TBI, NIT Campus, Kozhikode, Kerala, India.

Page 23: Scope of variable

In C++

Int main()

{

Private:

Protected:

Public:

}

Page 24: Scope of variable

In java

Int main()

{

Default:

Private:

Protected:

Public:

}