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

• 10-27-2002
correlcj
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.
• 10-27-2002
ammar
What do you mean by:
Quote:

range of values stored into a integer
I don't get it?
• 10-27-2002
RoD
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; }```
• 10-27-2002
Magos
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; }```
• 10-27-2002
Prelude
> 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
• 10-28-2002
correlcj
Thanks everybody for the help!!!
Thanks prelude, that really helped me understand.
:D