You are viewing a single comment's thread. Return to all comments →
First of all thanks for sharing your solution. I really appreciate it. But i found a bug. There is no exit condition for the first while loop. It will keep writing in the unauthorised memory and crash. It should be like this.
int *A = new int[N];
while(cin>>A[i++] && (i < N));
while(cout<<A[--N]<<' ' && N);
The firts while loop finishes when cin reads EOF, i.e. when cin finishes to read the whole input stream.
Another way is using scanf from C, it returns the number of input data assigned or the defined macro EOF (-1) when there is nothing less to read, so you can do the next one:
Those are the way of reading in c++ the whole input, there is challenges where the input size is not given
Sorry my english.
yes!!helped a lot
What exactly is delete A ??
it is to delete the dynamically allocated memory from heap.