I have the following code snippet:
#include<stdio.h>
void read(int a[ ],int n)
{
static int p=n;
if(n!=0)
{
printf("enter element %d: ",p-n);
scanf("%d",&a[p-n]);
read(a,n-1);
}
}
int main()
{
int a[10],n;
printf("enter n: ");
scanf("%d",&n);
read(a,n);
}
I keep getting the error: initializer element is not constant
.
Isn't n constant by the time the function compiles?
Edit: Problem: How to set the value of a static variable(if it isn't set) within a function?