# Thread: possible to have pointers in bitset?

1. you are right in saying t1 is pointing to t2, but go and check &t1 and &t2,
they are of different memory allocation, this is the weakness of bitset. you can only point to t2 but what if you want to store the memory of t2?
No, that is not a weakness of bitset. &t1 is the address of t1. &t2 is the address of t2. t1 and t2 contain addresses, and the address contained by t1 is the same as the address contained by t2 because they point to the same array. The address of t1 and the address of t2, on the other hand, are different, because they are not the same pointer. This applies even if t1 and t2 are int*s instead of bitset<8>*s.

now go run your code in data type int, you will find that &t1 == &t2
I agree, if 0012FF70 == 0012FF6C, upon which I have a proof that all integers are equal

Oh, for the record I ran my tests in MSVC8, from Microsoft Visual C++ 2005 Express.

2. >but &t1 != &t2
That's true whether you're talking ints or bitsets. &t1 means the address of the pointer, not where the pointer points. Run the second code you posted above that allocates an int array.

3. ok, i understand what you guys are explaining, thanks! it's my mistake, thanks for your help! =)

4. you can only point to t2 but what if you want to store the memory of t2?
If you wanted to store the address of t2 in t1, you would make t1 a bitset<8>** (or int**, as the case may be). For example:
Code:
```#include <bitset>
#include <iostream>

int main()
{
const std::size_t array_size = 10;
std::bitset<8>* t2;
std::bitset<8>** t1;

t2 = new std::bitset<8>[array_size];
t1 = &t2; // store the address of t2
std::cout << *t1 << std::endl;
std::cout << t2 << std::endl;
delete[] t2;
}```

5. int *t1; // a pointer

t1 is empty coz t1 is suppose to be pointer and it has not point to anything. so we can change t1 ( which stores the addresss )
Well, to be precise t1 points to garbage, you should set it to 0 (or NULL, which is synonymous with 0 in C++) if you want it to be a null pointer (and thus not point to "anything"). Eventually, t1 does store an address, but it stores the address of an int (the first int in an array of ints, and thus it points to that array).

but when we have

bitset<8> *t1;

t1 is not empty, it has a address, it only serves to point, but you cannot change its address
t1 here also points to garbage, until the point:
t1 = t2;
where it then points to the same array of bitset<8>s as t2 points to. Basically, the address in t2 is copied to t1, but the address of t1 and t2 are different.

You are right to say that you cannot change its address, but you can change what it points to (and thus change the address it contains).

then what is the difference if i'm using bitset or char? or either way works?

7. Originally Posted by swoopy
It depends on what you are comfortable using. Either way will work.
The good part of a bitset is that you know you are dealing with n number of bits (even if internally there are bits unused), and you can access bits using a higher level interface.

8. 2 diffrent variables can never have the same adress? :/ atleast i tought so.

9. >2 diffrent variables can never have the same adress?
True except for unions, where members of the union share the same address.