dimension question



Hi everybody,
I'm newbie at fortran. So I have a question about 'dimention'. Here is
an example of code to show problem.
ccccccccccccccccccccccccccccccccccccccccccccccccc
program dimtest
c
integer n, maxn
parameter(maxn=100)
real a
dimension a(maxn, maxn)
c
n = 2
a(1,1) = 1
a(1,2) = 2
a(2,1) = 3
a(2,2) = 4
call test(a, n)
end
ccccccccccccccccccccccccccccccccccccccccccccccccc
subroutine test(a, n)
integer n
real a
c problem is in the next string
dimension a(n, n)
c but in this case everithing is fine
c dimension a(100, n)
print *, a(1,1), a(1,2), a(2,1), a(2,2)
end
ccccccccccccccccccccccccccccccccccccccccccccccccc
My expected output is:
1.000000 2.000000 3.000000 4.000000
But in above test program output is like this:
1.000000 0.000000 3.000000 0.000000
So my first question is "why is it so critical to declare the first
dimension of a multidimension array as big as initial declaration
was?"
I used f95 and f77 compilers from gcc suite on linux.
The second question is "what the best practice to solve such
problems?"
Thanks for any advice

.