12,634,982 members (29,094 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 Arndt153.1K
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;
}```

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard MacCutchan 186 CPallini 175 OriginalGriff 128 F-ES Sitecore 65 ppolymorphe 59
 OriginalGriff 2,412 ppolymorphe 1,311 Peter Leow 1,029 CPallini 806 John Simmons / outlaw programmer 770

Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 11 Dec 2012