arrays.. what is the difference between these two evaluations ?

Oct 29, 2016 at 3:41pm
gives me the same output of input value at index 0 =9

1
2
3
4
   int inputVal = 9
   int itemsRead =0;
   array.resize( array.size( ) * 2 + 1 ) ;
   array[ itemsRead++ ] = inputVal;


1
2
3
4
   int inputVal = 9
   int itemsRead =0;
   array.resize( array.size( ) * 2 + 1 ) ;
   array[ itemsRead ] = inputVal;
Last edited on Oct 29, 2016 at 3:42pm
Oct 29, 2016 at 5:11pm
The only difference will be the value of itemsRead after the snippets. After the first snippet itemsRead will be 1 and after the second itemsRead will be zero.

Nov 1, 2016 at 11:51am
so it adds up after assigning it to array[0] ??
Nov 1, 2016 at 11:56am
In the first, 'itemsRead' is incremented after 9 is assigned to the 0th index.
In the second, 'items'Read' remains a 0 even after the assignment.
Topic archived. No new replies allowed.