if I want choose a random value that have 0 or 1 just
HTML Code:
rand() & 1;
thanks..
|
Light Poster
|
|
| 8Mar2011,03:42 | #1 |
|
hi..
if I want choose a random value that have 0 or 1 just HTML Code:
rand() & 1; thanks.. |
|
Mentor
|
![]() |
| 8Mar2011,23:20 | #2 |
|
What happens if you try it?
|
|
Light Poster
|
|
| 9Mar2011,18:05 | #3 |
|
its work good but relly i dont understand whay !!
I have aprublem .. i declerat apointer to pointer variable.. then I wan but this variable=null; I got error I dont know whay?? ex: int **T; *T= NULL; is this an error ?? |
|
Mentor
|
![]() |
| 9Mar2011,20:26 | #4 |
|
The rand() works because & is a bitwise operator, so &1 just takes the least significant bit. Look at the binary for the return value; if the results of rand() are, say, 10,5,3,17,6,4,21 then the LSB for those results are 0,1,1,1,0,0,1.
*T=NULL is an error because you haven't defined *T anywhere. When you create a pointer, you allocate space for the pointer itself but you don't allocate space for what that pointer points to. So when you write to *T, after defining just int **T, you're writing NULL to an unknown location in memory. So if you do: int T; int *pT=&T; int **ppT=&pt; THEN you can write to T, *pT and **ppT.
fulla
like this
|