Give more than one value to one variable?

Jul 16, 2012 at 7:00am
I want to give the variable X some values, let's say: 1,2,3

Then I want to check if X has the value 2 or not?

Is it possible? How can write it?

Thanks!
Jul 16, 2012 at 7:13am
an integer/double/float variable can store only one value at a time.
say if you do this
int x=0;
x=1;
x=2;
cout<<x;

you will get 2 as an output.
to store multiple values you can use array.
ie.
int x[3];
x[0]=1;
x[1]=2;
x[2]=3;
Jul 16, 2012 at 9:06am
you can use arrays, std::arays, std::vectors, std::deques, std::lists, std::forward_lists, std::basic_strings, std::valarrays, or std::tuples.
Jul 17, 2012 at 6:48am
Thanks guys, I guess I should start study arrays now!

Jul 20, 2012 at 8:55pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    int x[3];
    x[0] = 1;
    x[1] = 2;
    x[2] = 3;

    for (int i = 0; i < 3; i++)
    {
        if (x[i] = 1)
            std::cout << "array of ints, x, is int value 1 at array index [" << i << "]" << std::endl;
    }
    return 0;
}
Last edited on Jul 20, 2012 at 8:56pm
Topic archived. No new replies allowed.