13,354,733 members (58,636 online)
Rate this:
See more:
```int abc[]={5,8,9};
int i;
for(i=0;i<= ;i++)
cout<<abc[i];```

my qestion what value i write in condition
Posted 11-Dec-12 4:40am
ALIWAZ407
Updated 11-Dec-12 4:49am
Jochen Arndt220.4K
v2
Eugen Podsypalnikov 11-Dec-12 9:49am

Try it :) :
for (i = 0; i < _countof(abc); i++) {
//..
}
VISH_a_CODE 11-Dec-12 10:03am

I think you should try to declare the array first, then try to initialize for loop.

Ex:
int abc[10]={5,8,9};
int i;
for(i=0;i<=5;i++)
cout<<abc[i];

I tried it. So try it out....:)
Sergey Alexandrovich Kryukov 11-Dec-12 11:44am

This is an incorrect question. As always, first you need to tell what do you want to achieve. Depending on that -- could be different expressions.
--SA

Rate this:

## Solution 1

You have 3 items in array, in this case, index can be 0, 1 or 2.
You can do the following test :
`for(i=0;i<=2;i++)`

or
`for(i=0;i<3;i++)`

or
`for(i=0;i<sizeof(abc)/sizeof(abc[0]);i++)`

the last one can only be used because the array size of abc is set at the definition of the variable (implicitely in this case, explicite will be "int abc[3];").
It cannot be used with those:
```int NbItems(int abc[]) { return sizeof(abc)/sizeof(abc[0]);}
int* abc; abc = new int[3];```
v2
Rate this:

## Solution 2

I think you can use
`int nSize = sizeof(abc)/sizeof(abc[0]);`

so the code is look like below
```#include <iostream.h>
int main()
{
int abc[]={5,8,9};
int i;
int nSize = sizeof(abc)/sizeof( abc[0] );
for(i=0; i < nSize ;i++ )
{
cout<<abc[i];
}
return 1;
}```

try it
http://stackoverflow.com/questions/2773328/how-to-find-the-size-of-integer-array
v2
Rate this:

## Solution 4

`for(i=0;i<sizeof(abc)/sizeof(abc[0]);i++)`
ThatsAlok 12-Dec-12 2:24am

don't know who voted one for you! however my 5pt will square it off
Rate this:

## Solution 3

```#include <iostream>
using namespace std;
int main()
{
int abc[]={5,8,9};
int i;
int nSize = sizeof(abc)/sizeof( abc[0] );
for(i=0; i < nSize ;i++ )
{
cout<<abc[i]<<endl;
}
return 0;
}```

Top Experts
Last 24hrsThis month
 OriginalGriff 201 Jochen Arndt 110 CPallini 90 F-ES Sitecore 75 ppolymorphe 60
 OriginalGriff 4,237 Jochen Arndt 1,291 ProgramFOX 1,268 Maciej Los 1,210 Karthik Bangalore 1,151