Why output is 10 rather not 9.
Code:
#include
using namespace std;
void main()
{
const size_t array_size=10;
int ia[array_size];
for (size_t ix=0;ix!=array_size;++ix)
ia[ix]=ix;
cout<
}
/*
my logic is:when + + X is equal to 10, you no longer perform the body of the loop statement
right result cout<
*/
thanks.

VulpesPosted Aug 6, 2012, 11:35 AM
It then produced a garbage result i.e. whatever is in the next memory slot after ia[9].
That's because ix will have been incremented to 10 just before the expression :
ix!=array_size
fails and the for loop exits.
Ken HPosted Aug 7, 2012, 3:57 AM
i think this compile system question.
thanks.
Hemant SrivastavaPosted Aug 7, 2012, 12:19 AM
Now the line cout<
So accessing out of scope element "ia[10]" will give any random output. It may be 10 or something else..
Ken HPosted Aug 6, 2012, 10:30 PM
#include
using namespace std;
void main()
{
const size_t array_size=10;
int ia[array_size];
size_t ix; /* now declared at function scope */
for (ix=0;ix!=array_size;++ix)
ia[ix]=ix;
cout<
/*
i think "cout<
*/
Hemant SrivastavaPosted Aug 6, 2012, 10:46 AM