Home > database >  Random value at time of output
Random value at time of output

Time:10-11

what is the extra value at the output terminal

I have written this recursive function in C that prints array elements, but when I run it I get an extra number as output like 634, 389, etc. Can someone please tell me why this is happening and how can I fix this?

CodePudding user response:

The first call to your function prints out arr[5] to which you didn't assign value so it takes the random value that is in that place in the memory. To fix your issue I would recommend calling function with array size - 1 so in your case

func(arr, 4);
  • Related