I'm using int er[3001]
. I'll be taking user input, but it is unlikely that entire array size will be used.
In a char
array / string, one would simply set a for loop testing arr[i] != \0
. How is this effect achieved for an int
array ?
I'm assuming using the same exact condition won't work?
I'm assuming using the same exact condition wont work ?
You're right in this, there's no default sentinel value for marking the end of integer array. You need to either:
-1
, when all expected inputs are non-negative) and get to the first invalid value location after the input.