I did some experiments by using a function call and declaring my matrix in a function and use to write '1' in every row and column. However after some time the program crashes and stops working.
example one: The matrix is declared every time it is called in a while loop
void func(int row, int col){
int matrix[row][col];
for....
write one in the matrix...
}
example two: The matrix is declared outside the function as a global
int matrix[row][col];
void func(){
for....
write one in the matrix...
}
main code
int main(){
while(1){
func(...);
}
}
My question to you is that my code crashes whenever my matrix is declared inside a function but does not crash whenever it is declared outside a function. Do you guys know why the problem is like this ? Isnt the matrix a temporal value in the function , meaning will it not be erased after the function has executed ?