Why do i have to use adressof operator to refer to a var in this code?( int &p and not int p?)
why does it do nothing if i use "int p" ?can i have a logic explanation
still learning the adressof thing...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <cstdlib>
using namespace std;
void changer(int &p)
{
p=rand() % 215;
}
#define vectorsize 20
int dudes[vectorsize];
int main()
{
cout << "dudes : " << endl;
for(int g=0; g<=vectorsize; g++)
{
changer(dudes[g]);
cout << "dude" << g << " is :" << dudes[g] << endl;
}
return 0;
}
|
i know that if i do
1 2
|
cout << &somevariable << endl;
|
it will give me the adress of that variable(something like 0x02348)
but what is the point of "adressof" in that other code i posted (int &p)?
Last edited on
Last edited on
thanks for your reply! sorry if i expressed myself in a confusing way