Scan an array without knowing length

sample input constraint = 1<arr size<1000
sample input: 1 2 3 4 5
sample output: 1 2 3 4 5

eg: arr[0]=1
arr[1]=2
arr[2]=3
arr[3]=4
arr[4]=5

sample input: 1001 92 31
sample output: 1001 92 31

How to scan an array whos input length is not known.
Last edited on
It should not be possible to not know its length. If its an array, you allocated it with

type arr[size];

and if its a pointer, you allocated it with

type *arr = new type(size);

In both cases, you have size.
You can get its length from sizeof tricks, but you should never need to do that.

Arrays do not grow as you use them, you must preallocate, same for pointers.

As said, vectors do what you describe, sort of, you have to call a function instead of direct access when adding new values, or pre-allocate like an array....

Last edited on
Topic archived. No new replies allowed.