SlideShare a Scribd company logo
Scope of variables
SCOPE OFVARIABLE
SOBIN JOSE
Sobin.jose@outlook.com
Sobinjose
Sobinjose
Disclaimer: This presentation is prepared by trainees of
baabtra.com as a part of mentoring program. This is not
official document of baabtra.com – Mentoring Partner
What are Variables in C
Variables in C have the same
meaning as variables in algebra
Eg: x = a + b
z + 2 = 3(y - 5)
variables in algebra are represented
by a single alphabetic character.
Variable names in c
1. May only consist of letters, digits,
and underscores
2. May be as long as you like, but only the
first 31 characters are significant
3. May not begin with a number
Naming Conventions
 Begin variable names with
lowercase letters
Use meaningful identifiers
Separate “words” within identifiers
with underscores or mixed upper and
lower case.
Eg: int int_a; char str_a;
 There are two places where variables
can be declared in C programming
language:
1. Inside a function or a block which is
called “local variables”
2. Outside of all functions which is called
“global variables”.
Local Variable
Variables that are declared
inside a function are called local
variables. They can be used only by
statements that are inside that
function . Local variables are not
known to functions outside their
own.
Eg:#include <stdio.h>
Void main ()
{
/* local variable declaration */
int int_ x, int_ y;
Int int_ c;
/* actual initialization */
int_ x = 5;
int_y = 20;
int_ c = int_x + int_ y;
printf ("value of x = %d, b = %d and
c= %dn", int_x, int_y, int_ c);
}
 Global variables are defined outside of a
function, usually on top of the program. The
global variables will hold their value through out
the lifetime of your program and they can be
accessed inside any of the functions defined for
the program.
A global variable can be accessed by any
function. That is, a global variable is available for
use through out your entire program after its
declaration.
Global Variables
Eg: #include <stdio.h>
/* global variable declaration */
int int_ g;
Int main ()
{
/* local variable declaration */
int int_ a, int_b;
/* actual initialization */
int_ a = 10;
int_ b = 20;
int_ g = int_ a + int_ b;
printf ("value of a = %d, b = %d and g =
%dn", int_ a, int_ b, int_ g);
return 0;
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.
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
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

More Related Content

What's hot (20)

DOC
Project 2 the second project involves/tutorialoutlet
PPTX
Procedural programming
DOCX
C language
PDF
POLITEKNIK MALAYSIA
PDF
POLITEKNIK MALAYSIA
PPT
Programming Methodology
PPT
C programming for Computing Techniques
PPTX
Introduction of C#
PPT
Introduction to Procedural Programming in C++
ODP
Me2011 presentation by Manfred Jeusfeld
PDF
DIG1108 Lesson 8
PPTX
Modular programming
PPT
developing complex_programs
PPT
recursive problem_solving
PPTX
Structure of c
PPTX
Modular programming
PDF
Fundamentals of programming)
PPTX
C Operators
PPTX
PPTX
C sharp fundamentals Part I
Project 2 the second project involves/tutorialoutlet
Procedural programming
C language
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Programming Methodology
C programming for Computing Techniques
Introduction of C#
Introduction to Procedural Programming in C++
Me2011 presentation by Manfred Jeusfeld
DIG1108 Lesson 8
Modular programming
developing complex_programs
recursive problem_solving
Structure of c
Modular programming
Fundamentals of programming)
C Operators
C sharp fundamentals Part I
Ad

Similar to Scope of variables (20)

PDF
CP c++ programing project Unit 1 intro.pdf
PPTX
C Programming Unit-1
PDF
C-PPT.pdf
PPTX
Unit-1 (introduction to c language).pptx
PPTX
C programming Training in Ambala ! Batra Computer Centre
PPTX
computer ppt group22222222222222222222 (1).pptx
PPTX
Basic Of C language
DOCX
Programming Global variable
PPT
Lecture 14 - Scope Rules
PPTX
Scope rules : local and global variables
PDF
Book management system
PDF
C programming
DOCX
C programming language Reference Note
PPT
Basics of c++
PPTX
C programming
PPTX
#Code2 create c++ for beginners
PDF
C programming.pdf
PPTX
C language ppt
CP c++ programing project Unit 1 intro.pdf
C Programming Unit-1
C-PPT.pdf
Unit-1 (introduction to c language).pptx
C programming Training in Ambala ! Batra Computer Centre
computer ppt group22222222222222222222 (1).pptx
Basic Of C language
Programming Global variable
Lecture 14 - Scope Rules
Scope rules : local and global variables
Book management system
C programming
C programming language Reference Note
Basics of c++
C programming
#Code2 create c++ for beginners
C programming.pdf
C language ppt
Ad

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

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Scope of variables

  • 3. Disclaimer: This presentation is prepared by trainees of baabtra.com as a part of mentoring program. This is not official document of baabtra.com – Mentoring Partner
  • 4. What are Variables in C Variables in C have the same meaning as variables in algebra Eg: x = a + b z + 2 = 3(y - 5) variables in algebra are represented by a single alphabetic character.
  • 5. Variable names in c 1. May only consist of letters, digits, and underscores 2. May be as long as you like, but only the first 31 characters are significant 3. May not begin with a number
  • 6. Naming Conventions  Begin variable names with lowercase letters Use meaningful identifiers Separate “words” within identifiers with underscores or mixed upper and lower case. Eg: int int_a; char str_a;
  • 7.  There are two places where variables can be declared in C programming language: 1. Inside a function or a block which is called “local variables” 2. Outside of all functions which is called “global variables”.
  • 8. Local Variable Variables that are declared inside a function are called local variables. They can be used only by statements that are inside that function . Local variables are not known to functions outside their own.
  • 9. Eg:#include <stdio.h> Void main () { /* local variable declaration */ int int_ x, int_ y; Int int_ c; /* actual initialization */ int_ x = 5; int_y = 20; int_ c = int_x + int_ y; printf ("value of x = %d, b = %d and c= %dn", int_x, int_y, int_ c); }
  • 10.  Global variables are defined outside of a function, usually on top of the program. The global variables will hold their value through out the lifetime of your program and they can be accessed inside any of the functions defined for the program. A global variable can be accessed by any function. That is, a global variable is available for use through out your entire program after its declaration. Global Variables
  • 11. Eg: #include <stdio.h> /* global variable declaration */ int int_ g; Int main () { /* local variable declaration */ int int_ a, int_b; /* actual initialization */ int_ a = 10; int_ b = 20; int_ g = int_ a + int_ b; printf ("value of a = %d, b = %d and g = %dn", int_ a, int_ b, int_ g); return 0;
  • 12. 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.
  • 13. 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
  • 14. 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