1. Static Storage Class
Storage
Default Initial Value
Scope
Life
Memory
0
Local to the block in which
the variable is defined
Variable persists between
different function calls
2. main( )
{
increment( ) ;
increment( ) ;
increment( ) ;
}
increment( )
{
auto int i = 1 ;
register int j = 1 ;
static int k = 1 ;
i++ ;
j++ ; k++ ;
printf ( ”%d %d %d”, i, j, k ) ;
2 2 2
2 2 3
2 2 4
}
3. When to Use Static
main( )
{
f( )
f( ) ;
p =
int a = 20 ;
return ( &a ) ;
}
printf ( ”%d”, *p ) ;
}
int *p ; int * f( ) ;
{
a p
20 250
250
int * f( ) char ** char ** ff (( iinntt **,, ffllooaatt ** )) ;;
static int a = 20 ;
4. External Storage Class
main( )
{
printf ( ”%d”, a ) ;
increment( ) ;
increment( ) ;
decrement( ) ;
printf ( ”%d”, a ) ;
}
increment( )
{
a++ ; printf ( ”%d”, a ) ;
} decrement( )
{
a-- ; printf ( ”%d”, a ) ;
}
10
11
12
11
11
int a = 10 ;
Output
5. Declaration V/s Definition main( )
{
extern int a ;
printf ( ”%d”, a ) ;
increment( ) ;
increment( ) ;
decrement( ) ;
printf ( ”%d”, a ) ;
ncrement( )
{
extern int a ;
float square ( float ) ;
float square ( float )
{
..
..
}
DDeeccllaarraattiioonn
} a++ ; printf ( ”%d”, a ) ;
decrement( )
{
extern int a ;
} a-- ; printf ( ”%d”, a ) ;
}i
int a = 10 ;
DDeeccllaarraattiioonn
DDeeccllaarraattiioonn
DDeeffiinniittiioonn
float square ( float ) ;
float square ( float )
{
..
..
}
DDeeffiinniittiioonn
6. Declaration V/s Definition main( )
{
extern int a ;
printf ( ”%d”, a ) ;
increment( ) ;
increment( ) ;
decrement( ) ;
printf ( ”%d”, a ) ;
extern int a ;
int a = 10 ;
decrement( )
{
extern int a ;
}i
ncrement( )
{
a++ ; printf ( ”%d”, a ) ;
}
a-- ; printf ( ”%d”, a ) ;
}
7. Declaration V/s Definition main( )
{
extern int a ;
printf ( ”%d”, a ) ;
increment( ) ;
increment( ) ;
decrement( ) ;
printf ( ”%d”, a ) ;
int a = 10 ;
increment( )
{
extern int a ;
decrement( )
{
extern int a ;
}
a++ ; printf ( ”%d”, a ) ;
}
a-- ; printf ( ”%d”, a ) ;
}
8. Two Types Of Conflicts
int a = 10 ;
main( )
{
int a = 20 ;
{
int a = 30 ;
printf ( ”%d”, a ) ;
}
printf ( ”%d”, a ) ;
}
printf ( ”%d”, a ) ;
30
20
9. External Storage Class
Storage
Default Initial Value
Scope
Life
Memory
0
Global
Till execution of the
program doesn’t end
10. Which is The Most Powerful
Automatic
Register
Static
External
All other cases
For frequently
used variables
If variable is to live
across function calls
If variable required by
all functions
11. Ctrl F9
F9
F7
F8
C Preprocessor
Compile and Execute
Compile
Step into
Step over
13. A Closer Look
Hand written program
Text Editor
C Source Code
Preprocessor
Expanded source code
Compiler
Object code
Linker
Executable code
C :
Helps in typing TC
WS4 . .
a program
WORKS
Helps in typing
a program
Expands the
source code
Expands the
source code
Converts expanded source
code into machine language
Converts expanded source
code into machine language
14. Why IDE
Editor
Preprocessor
Compiler
Linker
Ctrl F9
TTuurrbboo CC//CC++++
Preprocesses,
Compiles, Links
and Executes
17. Unresolved
Externals
gotorc( - , - )
{
-
-
-
} Compiler
main( )
{
-
-
-
}
machine language
code of gotorc( )
machine language
code of main( )
Error Why?
18. Solution
m/c language code
of gotorc( )
m/c language code
of main( )
m/c language code
of clrscr( )
m/c language code
of printf( )
LLiinnkkeerr
Executable code
19. Your wish
# include ”goto.c”
# include goto.c
C :
TC
WS4 . .
WORKS
INCLUDE
INCLUDE DIRECTORIES
LIBRARY DIRECTORIES
C: TC INCLUDE
C: TC LIB
C: TC WORKS
C: TC
OUTPUT DIRECTORY
SOURCE DIRECTORIES