Search This Blog

Friday, October 8, 2010

Interview Questions

1. Explain Static variable and Static function

- A variable declared with static is initialized only once.
- Static variable maintains its value in different function calls.
- Static variable is locally globalized i.e. different functions with in a module can able to access the static variable.
- Static variable can be declared with in a function like auto variable or out side the function like global variable.
- Functions declared with static with in the module may only called by other functions in that module. (If you don't want a program to access your variables or functions, you use static which tells the compiler that this variable or function cannot be used outside of this module.)

2. What is extern keyword.

- Extern is a keyword used to access the global variables or functions in other modules.
- Extern keyword is for declaration not for definition. Extern cannot allocate memory that must be done by global variable.
eg: in main.c
int glb=0; //global variable definition.
main()
{
glb=10;
function();
}
in func.c
function()
{
extern int glb_var; //extern definition
glb_var+=10;
}

3. Difference between global and static variable.

- Scope(visibility) of static variable is with in a module but life(object is still in the memory) is entire program.
- Scope and life of a global variable is entire program.
- Global variables and static variables are created in Heap area.
- Static variables are initialized with zero.

4. What is reentrance procedure.

- A reentrant procedure is one in which a single copy of the program code can be shared by multiple users during the same period of time.
- Re entrance has two key aspects:
= The program code cannot modify itself and
= The local data for each user must be stored separately.
- In a shared system, reentrancy allows more efficient use of main memory: One copy of the program code is kept in main memory, but more than one application can call the procedure.
- A reentrant procedure must have a permanent part( the instructions that make up the procedure) and a temporary part(a pointer back to the calling program as well as memory for local variables used by the program).


No comments:

Post a Comment