Topics

6/recent/ticker-posts

Types of Storage classes in C language (Part 2)

 Storage classes other types: 

The remaining other storage classes in the c language are 
3. Static storage class 
4. External Storage class

3. Static Storage class: 

In this static storage class just the user should include a static keyword in front of a data type that the variable will wont occupy more and more storage than dynamic storage class. The Syntax for these Static storage class is as follows 

Syntax:  

    static int a;

Program to show how static storage class is used: 

#include<stdio.h>

int main()

{

static  int  a;

static float b;

static char  ch;

            printf(“\n %d  %f  %c”,a,b,ch);

return 0;

}

 

here in the above example the default values of the data types are checked. 


Important points to know: 


1. All static variable of the program acquires memory logically at the time of creation of exe file.


2. Static memory is a part of exe file.


3. Compiler allocates virtual memory for all static variable of the program inside the exe file.


4. These variables acquires memory physically when exe file is loaded into memory for execution.


5. After loading exe file into memory main() function execution starts. Hence all static variables acquires memory before going execute main().


6. These variables deletes from the memory when program is stopped. Hence life of the static              variable as long as program is running.


7. Life is as long program is running but scope is within the bock in which it is declared.



 


Higher order memory space :

To store all command line arguments and OS environment variable.

 

Stack Memory space :

            To store all local auto storage class variables.

            Memory allocation is LIFO ( last In First Out ) based.

This memory space grows automatically as long as sharable memory available for it.

If stack filled it raises stack over flow exception.

 

Shared Memory space:

 

            This memory can be shared by stack and heap.

 

Heap Memory space:

            This memory space is for dynamic memory management.

            In this memory allocation, resizing and de-allocating is always at runtime.

            This memory space grows automatically as long as sharable memory available for it.

 

Global Memory space:

This memory space is to store global variables. It’s size is a fixed one, it will be decided at the time of creating exe file as per the no of global variables declaration in C-Application.

 

Static Memory space:

This memory is to store the static variables. It’s size is a fixed one, it will be decided at the time of creating exe file as per the no of static variables declaration in C-Application.

 

Text Memory Space:

            This memory contains all C-Program instructions, C-Libraries and OS Libraries linked with the exe file.

 





name.c   à  called as source code file.

name.obj à called as object file

name.exe à called as executable file.

 

Pre-Processor:

            it will process the statement which are starting with #.

            The statements which are starting with # are called as pre-processor directives.

            Eg:

                        #define N 20

                        #include<stdio.h>

 

Before going to compile C-Program, pre-processor process all  # statements (pre-processor directives ).

Simply  pre-processor  takes the constants values and dumps at the location, where the constants are presented in program.

It also reads the contents of include files ( header files ) and dump into program.

 

Assembler:

            C-Program can also have assembly language coding as per the requirements.

If C-Program contains, assembler instructions then, before going to compile the C-Program assembler invokes and converts all assembly language instructions into C-Language instructions.

 

Compiler:

            C-Compiler, check the syntax of c-program and converts binary code, then generates object file.

 

Linker :

            Linker links all object files, C-Library, OS Libraries and Hardware information, then finally generates exe file.

 

           

Source Code à it is a code developed by the C-Programmer.

 

Object Codeà it is generated by the C-Compiler. it is in the form binary code.

                        Object file contains only C-Program instructions.

 

Executable file Ã  It is generated by the linker. It also contains binary code.

                       

The difference between object file and exe file is that,

 

1)Object file contains

only binary instructions of C-Program,

  

Exe file contains 

1) Binary instructions of C-Program  2) C-Library  3) OS Library  and  4) Hard information.

                       

Object file is not a  prepared file

 

Exe file is a prepared file and ready to execute.

Exe file is a platform ( Operating system ) dependent,  since it contains OS Library.

 

Post a Comment

0 Comments