Home > Blockchain >  Changed value of variables in debugging
Changed value of variables in debugging

Time:09-26

I'm trying to fill two dimensional array When debugging for-loop, value of a and num is changed. I don't know why value is changed.

int main(void)
{
    int num,t; 
    int count = 1; 
    int a = 0, b = 0; 
    int arr[num][num]; 

    printf("Input Number : ");
    scanf("%d",&num);
    
    t = num;    
    
    for(int i = 0 ; i < t ; i  )    
    {
        arr[a][b] = count;
        b  ;
        count  ;
    }
}

CodePudding user response:

You are defining your array with undefined values since num has not been assigned a value. You should assign num a value before defining the array and you should at least see more expected results.

CodePudding user response:

Your program needs the num to be assigned a value before declaring the array that is supposed to store the value contained in num variable. Otherwise, it won't execute properly.

printf("Input Number : ");
scanf("%d",&num);

before

int arr[num][num]; 

Hope that helps!

  •  Tags:  
  • c
  • Related