# Thread: Can yoou return a range of values stored into a integer?

1. ## Can you return a range of values stored into an array of integer?

Can someone give me an example of this too? Sorry, but i din't know if to open a new thread or not since its a different kind of question?
sorry for the confusion, i edited it.

2. What do you mean by:
range of values stored into a integer
I don't get it?

3. i don't either but this would return a range :

Code:
```#include <iostream.h>

int main()
{
for (int x = 1; x <=100; x++)
{
cout<<x<<endl;
}

return 0;
}```

4. You can only store 1 value in an integer, though you could use bitshifting and masking to store more:
Code:
```int SetValues(short First, short Last)
{
int Var;
Var = First;
Var |= (Last << 16);
return Var;
}

short GetFirst(int Var)
{
return Var & 0x00FF;
}

short GetLast(int Var)
{
return Var & 0xFF00;
}```
If you really want to return a range, you could use a structure:
Code:
```typedef struct
{
int First;
int Last;
}RANGE;

RANGE GetRangeFunction()
{
RANGE Range;
Range.First = 12;
Range.Last = 36;
return Range;
}```

5. > Can you return a range of values stored into an array of integer?
An array of integers is a range of values. Just return a pointer to the array:
Code:
```#include <iostream>

int *f()
{
int *range = new int[5];

for ( int i = 0; i < 5; ++i )
range[i] = i;

return range;
}

int main()
{
int *r = f();

for ( int i = 0; i < 5; ++i )
std::cout<< r[i] <<std::endl;

delete[] r;

std::cin.get();
}```
-Prelude

6. ## Thanks everybody for the help!!!

Thanks prelude, that really helped me understand.