CSO101: Computer Programming
Lecture – 16
O.S.L. Bhavana
Multi-dimensional Arrays
Multi-dimensional arrays as function arguments
Ex: Function declaration: int max(int a[2][3]);
Function call: max(a);
Ex: incorrect function declaration: int max(int a[][]); //second dim missing
Multi-dimensional arrays as function arguments
Storage Classes
Storage Classes
Auto
Register
Static Storage Duration
Static Storage Duration: Global Variables
void f(){......}
void g(){......}
main(){....} // variable a can be used by f, g and main
Static Storage Duration: Global Variables
which tells the compiler that there exists a function with name foo and its definition is somewhere else�
Static Storage Duration: Static Keyword
Static Keyword
void f_1(void);
int main( )
{func(); func();func(); } // prints 1,2,3
void func(void)
{
static int count = 1;
printf(“%d\n”, count);
count ++;
}
�
Static Keyword
void f_1(void);
int main( )
{f_1(); f_1();f_1(); } // prints 1,1,1
void f_1(void)
{
static int count = 1; count=1;
printf(“%d\n”, count);
count ++;
}
�
Useful in counting the number of recursive calls a function has
Static Keyword
int fib(int n) //function to print the n^th fibonacci number
{
static int counter = 0;
counter ++;
printf(“In fib with counter = %d \n”, counter);
if (n==0 || n==1) return n;
else return fib(n-2)+ fib(n-1);
}
Number of recursive calls in fib(4)?
�