SlideShare a Scribd company logo
1 of 17
Anu
anusdhar4@gmail.com
www.facebook.com/AnuSasidharan
twitter.com/Anu
in.linkedin.com/in/Anu
9400892764
SCOPE OF VARIABLES IN C
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
•Region of the program where a defined variable can
have its existence .
•3 places where variables can be declared in C
programming language:
 Inside a function or a block -local variables
 Outside of all functions - global variables
 In the definition of function parameters-formal parameters.
What Actually Scope Of A Variable Mean??
What are local variables ???
•It exists only inside the specific function that creates them.
•They are unknown to other functions and to the main
program.
•Local variables cease to exist once the function that created
them is completed.
•They are recreated each time a function is executed or
called.
EXAMPLE
int sum(int a, int b)
{
int tot;
tot=a+b;
}
•These variables can be accessed by any function
comprising the program.
•They do not get recreated if the function is recalled.
What are global variables
???
EXAMPLE
#include<stdio.h>
int sum(int, int);
int tot;
main()
{
int a=10,b=5;
tot=sum(a,b);
}
sum(int c, int d)
{
tot=c+d;
return tot;
}
#include <stdio.h>
int sqr( int x ) ;
main()
{
int i , j ;
sqr( i ) ;
printf( "%d %dn", i, j ) ;
}
int sqr( int x )
{
j = x * x ; }
SIMPLE EXAMPLE ILLUSTRATING
SCOPE OF VARIABLES
CORRECT METHOD
#include <stdio.h>
int sqr( int x ) ;
main()
{
int i , j ;
sqr( i ) ;
printf( "%d %dn", i, j ) ;
}
int sqr( int x )
{ int j;
j= x * x ; }
LOCAL VARIABLES Vs
GLOBAL VARIABLES
Using local variables allows to focus attention on smaller more
manageable pieces of the program. Globals forces 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
globals of the same name.
The effects of algorithm steps reduces the cases of unexpected
behavior.
Localizing the effects of algorithm steps makes the program
easier for others to understand.
 If the two functions need to communicate, then we
generally need global variables.
If the entire program is built around some central data
and if access to that data is needed in nearly every
function and particularly if that is a large data structure,
then it makes sense to make such data global.
When do we use global variables ???
A Final Implementation with an Example
#include <stdio.h>
int f1( void ) ;
int f2( int x, int a ) ;
int a ;
main()
{ int a, b, c ;
a = 7 ;
b = f1() ;
c = f2( a, b ) ;
printf( "%dn %dn %dn", a, b, c ) ;
}
int f1( void )
{ a = 12 ;
printf( "%dn ", a ) ; return( a + 5 ) ;
}
int f2( int x, int a )
{ printf( "%dn ", a ) ; return( x * a ) ;
}
OUTPUT
12
17
7
17
119
a=7,12
a=7,12,7
b=17
x=7
a=7,12,7,17
c=119
CONCLUSION
Scope of variable was explained. It defines the existence or
the availability of variables in a program.
Types of scope was discussed. Scope depends upon the type
of variable declaration.
Global and Local variables were briefly explained.
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? Do
an online course @ baabtra.com. We provide development, testing
and production environments just like in the industry to practice.
The courses are so structured to make a quick, good software
professional.
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
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
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
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot

FIT-Unit3 chapter 1 -computer program
FIT-Unit3 chapter 1 -computer programFIT-Unit3 chapter 1 -computer program
FIT-Unit3 chapter 1 -computer programraksharao
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithmsStudent
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartRabin BK
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow chartsPraveen M Jigajinni
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartSachin Goyani
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of PrecedenceMuhammad Hammad Waseem
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventionssaranyatdr
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)Puneet narula
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingDhrumil Panchal
 
connecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringconnecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringRam Kumar K R
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithemehsanullah786
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowchartsSamuel Igbanogu
 
Part17 radio button using vb.net 2012
Part17 radio button using vb.net 2012Part17 radio button using vb.net 2012
Part17 radio button using vb.net 2012Girija Muscut
 
Part18 checkbox using vb.net
Part18 checkbox using vb.netPart18 checkbox using vb.net
Part18 checkbox using vb.netGirija Muscut
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithmDHANIK VIKRANT
 

What's hot (20)

Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
FIT-Unit3 chapter 1 -computer program
FIT-Unit3 chapter 1 -computer programFIT-Unit3 chapter 1 -computer program
FIT-Unit3 chapter 1 -computer program
 
Flowcharts and algorithms
Flowcharts and algorithmsFlowcharts and algorithms
Flowcharts and algorithms
 
Algorithms & flowcharts
Algorithms & flowchartsAlgorithms & flowcharts
Algorithms & flowcharts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Chapter 6 algorithms and flow charts
Chapter 6  algorithms and flow chartsChapter 6  algorithms and flow charts
Chapter 6 algorithms and flow charts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
C Operators
C OperatorsC Operators
C Operators
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
 
Flowcharting and Algorithm
Flowcharting and Algorithm Flowcharting and Algorithm
Flowcharting and Algorithm
 
Csc 130 class 2 problem analysis and flow charts(2)
Csc 130 class 2   problem analysis and flow charts(2)Csc 130 class 2   problem analysis and flow charts(2)
Csc 130 class 2 problem analysis and flow charts(2)
 
Type conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programmingType conversion, precedence, associativity in c programming
Type conversion, precedence, associativity in c programming
 
connecting discrete mathematics and software engineering
connecting discrete mathematics and software engineeringconnecting discrete mathematics and software engineering
connecting discrete mathematics and software engineering
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Algorithms and flowcharts
Algorithms and flowchartsAlgorithms and flowcharts
Algorithms and flowcharts
 
Part17 radio button using vb.net 2012
Part17 radio button using vb.net 2012Part17 radio button using vb.net 2012
Part17 radio button using vb.net 2012
 
Part18 checkbox using vb.net
Part18 checkbox using vb.netPart18 checkbox using vb.net
Part18 checkbox using vb.net
 
Flowchart and algorithm
Flowchart and algorithmFlowchart and algorithm
Flowchart and algorithm
 

Viewers also liked

Viewers also liked (19)

Code optimization
Code optimization Code optimization
Code optimization
 
Database
DatabaseDatabase
Database
 
Php.ini
Php.iniPhp.ini
Php.ini
 
Database normalisation
Database normalisationDatabase normalisation
Database normalisation
 
Cpu and its execution statements
Cpu and its execution statementsCpu and its execution statements
Cpu and its execution statements
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Baabtra.com enterprise lms
Baabtra.com   enterprise lmsBaabtra.com   enterprise lms
Baabtra.com enterprise lms
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Oops in java
Oops in javaOops in java
Oops in java
 
Session and cookies ,get and post methods
Session and cookies ,get and post methodsSession and cookies ,get and post methods
Session and cookies ,get and post methods
 
Baabtra.com little coder chapter - 2
Baabtra.com little coder   chapter - 2Baabtra.com little coder   chapter - 2
Baabtra.com little coder chapter - 2
 
Php.ini
Php.iniPhp.ini
Php.ini
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Oculus rift bababte presentation
Oculus rift   bababte presentationOculus rift   bababte presentation
Oculus rift bababte presentation
 
Baabtra.com little coder chapter - 5
Baabtra.com little coder   chapter - 5Baabtra.com little coder   chapter - 5
Baabtra.com little coder chapter - 5
 
Jquery
JqueryJquery
Jquery
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Halo
HaloHalo
Halo
 
How to hack or what is ethical hacking
How to hack or what is ethical hackingHow to hack or what is ethical hacking
How to hack or what is ethical hacking
 

Similar to Scope of Variables in C Explained

Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semKavita Dagar
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural ProgrammingDeepam Aggarwal
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of ckinish kumar
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxurvashipundir04
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogrammingLuis Atencio
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variableimtiazalijoono
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignmentAhmad Kamal
 
Contact management system
Contact management systemContact management system
Contact management systemSHARDA SHARAN
 
Program understanding: What programmers really want
Program understanding: What programmers really wantProgram understanding: What programmers really want
Program understanding: What programmers really wantEinar Høst
 

Similar to Scope of Variables in C Explained (20)

Procedural programming
Procedural programmingProcedural programming
Procedural programming
 
Scope of variable
Scope of variableScope of variable
Scope of variable
 
SPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in CSPL 9 | Scope of Variables in C
SPL 9 | Scope of Variables in C
 
Book management system
Book management systemBook management system
Book management system
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
scope of variables
scope of variablesscope of variables
scope of variables
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
Monolithic and Procedural Programming
Monolithic and Procedural ProgrammingMonolithic and Procedural Programming
Monolithic and Procedural Programming
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Contact management system
Contact management systemContact management system
Contact management system
 
Program understanding: What programmers really want
Program understanding: What programmers really wantProgram understanding: What programmers really want
Program understanding: What programmers really want
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Scope of Variables in C Explained

  • 1.
  • 3. 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
  • 4. •Region of the program where a defined variable can have its existence . •3 places where variables can be declared in C programming language:  Inside a function or a block -local variables  Outside of all functions - global variables  In the definition of function parameters-formal parameters. What Actually Scope Of A Variable Mean??
  • 5. What are local variables ??? •It exists only inside the specific function that creates them. •They are unknown to other functions and to the main program. •Local variables cease to exist once the function that created them is completed. •They are recreated each time a function is executed or called.
  • 6. EXAMPLE int sum(int a, int b) { int tot; tot=a+b; }
  • 7. •These variables can be accessed by any function comprising the program. •They do not get recreated if the function is recalled. What are global variables ???
  • 8. EXAMPLE #include<stdio.h> int sum(int, int); int tot; main() { int a=10,b=5; tot=sum(a,b); } sum(int c, int d) { tot=c+d; return tot; }
  • 9. #include <stdio.h> int sqr( int x ) ; main() { int i , j ; sqr( i ) ; printf( "%d %dn", i, j ) ; } int sqr( int x ) { j = x * x ; } SIMPLE EXAMPLE ILLUSTRATING SCOPE OF VARIABLES
  • 10. CORRECT METHOD #include <stdio.h> int sqr( int x ) ; main() { int i , j ; sqr( i ) ; printf( "%d %dn", i, j ) ; } int sqr( int x ) { int j; j= x * x ; }
  • 11. LOCAL VARIABLES Vs GLOBAL VARIABLES Using local variables allows to focus attention on smaller more manageable pieces of the program. Globals forces 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 globals of the same name. The effects of algorithm steps reduces the cases of unexpected behavior. Localizing the effects of algorithm steps makes the program easier for others to understand.
  • 12.  If the two functions need to communicate, then we generally need global variables. If the entire program is built around some central data and if access to that data is needed in nearly every function and particularly if that is a large data structure, then it makes sense to make such data global. When do we use global variables ???
  • 13. A Final Implementation with an Example #include <stdio.h> int f1( void ) ; int f2( int x, int a ) ; int a ; main() { int a, b, c ; a = 7 ; b = f1() ; c = f2( a, b ) ; printf( "%dn %dn %dn", a, b, c ) ; } int f1( void ) { a = 12 ; printf( "%dn ", a ) ; return( a + 5 ) ; } int f2( int x, int a ) { printf( "%dn ", a ) ; return( x * a ) ; } OUTPUT 12 17 7 17 119 a=7,12 a=7,12,7 b=17 x=7 a=7,12,7,17 c=119
  • 14. CONCLUSION Scope of variable was explained. It defines the existence or the availability of variables in a program. Types of scope was discussed. Scope depends upon the type of variable declaration. Global and Local variables were briefly explained.
  • 15. 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? Do an online course @ baabtra.com. We provide development, testing and production environments just like in the industry to practice. The courses are so structured to make a quick, good software professional.
  • 16. 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 Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 17. 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 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com