-
pointers.......
i just learned them ( somewhat) and i am very confused about the return value i recieve....
this is what i made, if anyone could explain why its NOT giving me 10 , i would greatly appreciate it.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void fn( int );
int main ()
{
cout<<" The value of intvar is:"<<fn<<endl;
return 0;
}
void fn( int intvar)
{
int intVar;
int *pintVar;
pintVar = & intVar;
*pintVar = 10;
}
it prints out 00401221
why????
-
It prints this because fn is a name of function... so the cout statement displays the addresss of the function fn()...
Well you can get your required result.. of changing a variable's value.. in another.. function...... check this code.. this can be used for the purpose...
Code:
#include <iostream.h>
#include <conio.h>
void fn( int &);
using std::cout;
using std::cin;
using std::endl;
int main ()
{
int intvar;
fn(intvar);
cout<<" The value of intvar is:"<<intvar<<endl;
return 0;
}
void fn( int &pintVar)
{
pintVar = 10;
}
-
Or you can make cout << fn(blabla)
and return a value in fn, so it can be displayed, the prototype will be:
int fn(blabla);