%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
Scope of variables in c ..by thanveer danish
1.
2. 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
3. SCOPE OF VARIABLES IN C
MUHAMMED THANVEER.M
kutubmadar@gmail.com
www.facebook.com/username
twitter.com/username
in.linkedin.com/in/profilename
9526960445
4. WHAT IS VARIABLE
A variable is nothing but a name given to a storage
area that our programs can manipulate. Each
variable in C has a specific type, which determines
the size and layout of the variable's memory; the
range of values that can be stored within that
memory; and the set of operations that can be
applied to the variable.
5. BASIC VARIABLE TYPES
Type Description
char
Typically a single octet(one
byte). This is an integer
type.
int
The most natural size of
integer for the machine.
float
A single-precision floating
point value.
double
A double-precision floating
point value.
void
Represents the absence of
type.
6. Variable Scope
An Objective-C program will consist of code divided
up into functions, classes and code structures (such
as do .. while and for loops). Invariably a typical
program will make extensive use of variables to
store and manipulate data. Once a variable has
been declared it may or may not be accessible to
other sections of the program code. This
accessibility depends on where and how the
variable was declared and where the code is that
needs to access it. This is known as variable scope
7. Local Variables
Variables that are declared inside a function or block
are called local variables
They can be used only by statements that are inside
that function or block of code.
Local variables are not known to functions outside
their own.
8. Following is the example using local variables.
Here all the variables a, b and c are local to main() function.
#include <stdio.h>
int main ()
{
/* local variable declaration */
int a, b;
int c;
/* actual initialization */
a = 10; b = 20;
c = a + b;
printf ("value of a = %d, b = %d and c = %dn", a, b, c);
return 0; }
9. Global Variables
Global variables are defined outside of a
function, usually on top of the program. The
global variables will hold their value throughout
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 throughout your entire program after its
declaration
10. o Example using global and local variables
#include <stdio.h>
/* global variable declaration */
int g;
int main ()
{
/* local variable declaration */
int a, b;
/* actual initialization */
a = 10;
b = 20;
g = a + b;
printf ("value of a = %d, b = %d and g = %dn", a, b, g);
return 0;
}
11. A program can have same name for local and global
variables but value of local variable inside a function
will take preference. Following is an example:
#include <stdio.h>
/* global variable declaration */
int g = 20;
int main ()
{
/* local variable declaration */
int g = 10;
printf ("value of g = %dn", g);
return 0;
}
When the above code is compiled and executed, it produces the following
result:
value of g = 10
12. 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
13. 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