While programming I have come to an unusual error. When I initialize an integer in a loop, sometimes it says that the expression is not valid, but at times it accepts it. This is my code which gives error:
int pow(int x,int n);
int main()
{
    int x,n,result;
    printf("Enter a number:\n");
    scanf("%d",&x);
    printf("Enter its power:\n");
    scanf("%d",&n);
    result=pow(x,n);
    printf("Result is %d\n",result);
    getch();
    return 0;
}
int pow(int x,int n)
{   
    for(int i=1;i<n;i++)   //<-- here it says that declaration syntax error
    x=x*i;
    return x;
}
While when i change it like this :
int pow(int x,int n)
{   
    int i;
    for(i=1;i<n;i++)  
    x=x*i;
    return x;
}