in opengl i know that there is a projection matrix and a modelview matrix.but then what is the current matrix?
in the code below,glLoadIdentity() is used to load identity matrix into what matrix?why is it needed?

The loadidentity call is similar to clearing a variable. Its is setting the current modelview matrix to identity.

Explanation:
Suppose you have a program which does this in the display function;

int x=0;
int dx=1;
void display(){
x+= dx; //similar to translate call
}

In the above code, the x variable will increment each time and then the object will move in the x direction 1 units. What we wanted was to shift the object to pos x=1; So the solution we do is this,

void display(){
x=0; //similar to loadidentity
x+= dx; //similar to translate call
}

NOw x will have a value of 1 and it will remain 1. I hope this helps u in understanding what is going on.