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.
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.
Last edited by correlcj; 10-27-2002 at 03:19 PM.
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee
What do you mean by:
I don't get it?range of values stored into a integer
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; }
You can only store 1 value in an integer, though you could use bitshifting and masking to store more:
If you really want to return a range, you could use a structure: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; }
Code:typedef struct { int First; int Last; }RANGE; RANGE GetRangeFunction() { RANGE Range; Range.First = 12; Range.Last = 36; return Range; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
> 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:
-PreludeCode:#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(); }
My best code is written with the delete key.
Thanks prelude, that really helped me understand.
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee