Invalad conversion from '*int' to 'int'

I am trying to make a random number generator. and when i compile it, it says:
Invalad conversion from 'int*' to 'int'.
Do you know whats going on and if you do can you explain it?

here's the code:
#include <iostream>

using namespace std;

int main()
{
int *a, b;
b=a;
cout <<a;
return 0;
}
a is a pointer to an integer, while b is an integer. What exactly are you trying to do? If you want to output the memory-location where a is pointing to, you can simply output a, or you could use typecasting:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
    int *a, b;
    b=(int)a;
    cout<<b<<endl;
    cout<<a;
    cin.ignore();
    return 0;
}


Btw. The memory location of a pointer isnt what you call a great generator for random numbers.
isn't the addresses of a pointer that points to an undefined address undefined?
No, I don't think so, aldo I'm not sure what you mean by undefined. Try this:
1
2
int a;
cout<<a;


Aldo 'a' isn't initialized, it holds a (unexpected) value. However, you can't use this to generate random numbers, because 'a' will probably have the same (unexpected) value next time you run the program.

You may want to google for 'generating random numbers' or someting like that, to see what algoritehms are possible. And you do know that there is a standard function available that generate random numbers, right?
Topic archived. No new replies allowed.