Declaration of dynamic array before getting array length
In dynamic allocation of arrays at runtime, when the array is declared before getting the array length, I encountered a behavior that could not explain.
In the following code, the user provides the length of the array, say 5
and then provides five space-separated numbers as input, say 4 3 7 2 1
. By printing length
after the for
loop we see that it changes.
Here is the code.
Declaration of dynamic array before getting array length
In dynamic allocation of arrays at runtime, when the array is declared before getting the array length, I encountered a behavior that could not explain.
In the following code, the user provides the length of the array, say 5
and then provides five space-separated numbers as input, say 4 3 7 2 1
. By printing length
after the for
loop we see that it changes.
Here is the code.