[Dev-C++] problem with using reference
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: faramarz y. <far...@ho...> - 2004-04-21 20:21:28
|
hi
i encounter a mysterous problem testing pointers and references in c++.
i wrote this file :
//*******************************************************************************
#include <iostream>
#include <cstdlib>
using namespace std;
void fv(int);
void fp(int*);
void fr(int&);
int main (int argc, char *argv[])
{
int x=10;
fv(x);
system("PAUSE");
fp(&x);
system("PAUSE");
fr(x);
system("PAUSE");
return 0;
}
void fv(int y)
{
y+=1;
cout<<endl<<"*********************************"<<endl;
cout<<endl<<"sending value to function"<<endl;
cout<<endl<<"y : "<<y;
cout<<endl<<"&y : "<<&y;
cout<<endl<<"*********************************"<<endl;
}
void fp(int* ipx)
{
*ipx+=2;
cout<<endl<<"*********************************"<<endl;
cout<<endl<<"sending pointer to function"<<endl;
cout<<endl<<"ipx : "<<ipx;
cout<<endl<<"*ipx : "<<*ipx;
cout<<endl<<"*********************************"<<endl;
}
void fr(int& irx)
{
irx+=3; //irx=irx+3;
cout<<endl<<"*********************************"<<endl;
cout<<endl<<"sending reference to function"<<endl;
cout<<endl<<"irx : "<<irx;
cout<<endl<<"&irx : "<<&irx;
cout<<endl<<"*********************************"<<endl;
}
//************************************************************************************
i expect these result :
//*********************************************************
y : 11
&y : 0x241ff38 //for example
ipx : 0x241ff5c //sth diferent from &y & it's ok
*ipx : 12
irx : 13 //but result in dev-c++ is irx : 15 ERROR
&irx : 0x241ff5c //equal to ipx and &x and it's ok
//*********************************************************
i add irx with 3 and it should be 13 now,
but as u can see it's 15
i'm very eager to hear from u and knowing the answer that wath the problem
is
thank u in advance
Faramarz Yari
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
|