Answer:
Scope:
The
scope of an identifier is a part of the program in which the identifier can be
used to access its object.
There
are different categories of scope:
(i)
File
scope
(ii)
Function
scope
(iii)
Block
scope
(iv)
Function-prototype
scope
These
categories depend on how and where identifiers are declared.
(i)
File
scope: File
scope identifiers, also known as globals, are declared outside of all blocks;
their scope is from the point of declaration to the end of the source file.
(ii)
Function
scope: The only identifiers having function scope are statement
labels. Label names can be used with goto statements anywhere in the function
in which the label is declared. Labels are declared implicitly by writing
label_name: followed by a statement. Label names must be unique within a
function.
(iii)
Block
scope: The scope of an identifier
with block (or local) scope starts at the declaration point and ends at the end
of the block containing the declaration (such block is known as the enclosing
block). Parameter declarations with a function definition also have block
scope, limited to the scope of the function body.
(iv)
Function-prototype
scope: Identifiers declared within the list of parameter
declarations in a function prototype (not as a part of a function definition)
have a function prototype scope. This scope ends at the end of the function
prototype.
Visibility:
The
visibility of an identifier is a region of the program source code from which
an identifier’s associated object can be legally accessed.
Scope
and visibility usually coincide, though there are circumstances under which an
object becomes temporarily hidden by the appearance of a duplicate identifier:
the object still exists but the original identifier cannot be used to access it
until the scope of the duplicate identifier ends.
Technically,
visibility cannot exceed a scope, but a scope can exceed visibility.
Lifetime:
The
lifetime of an object is the time in which memory is reserved while the program
is executing. There are three object lifetimes:
(i)static Objects
(ii)automatic Objects
(iii)dynamic Objects
(i)Static Objects:
The
memory for static objects is allocated at compile/link time. Their address is
fixed by the linker based on the linker control file (LCF). You may know
this file by another name such as linker-script file, linker configuration file
or even scatter-loading description file. The LCF file defines the physical
memory layout (Flash/SRAM) and placement of the different program regions.
(ii)Dynamic Objects:
Strictly speaking
(according to the C standard) dynamically allocated objects are also called
automatics. However, it is important to differentiate between this type of
object and automatics for two reasons:
Ø The memory is
allocated from a different memory area (the heap not the stack).
Ø The lifetime is under
the control of the programmer rather than the C run-time system.