Should i pass address of pointer or just pointer???
Firstly see the code:
Code:
#include<iostream>
#include<conio.h>
using namespace std;
typedef struct temp
{
int data;
} T;
void setframe2( T **tp)
{
(*tp)->data = 2;
}
void setframe3( T *tp)
{
tp->data = 3;
}
void setframe( T *tp)
{
tp->data = 1;
setframe2(&tp);
setframe3(tp);
}
void main()
{
T tvar;
tvar.data=0;
cout<<"\nValue of data before call to setframe "<<tvar.data;
setframe(&tvar);
cout<<"\nValue of data after call to setframe "<<tvar.data;
getch();
}
OUTPUT
Value of data before call to setframe 0
Value of data after call to setframe 3
In setframe i have T *tp
when calling to setframe2, i am passing its address
setframe2(&tp);
and in setframe2 , tp->data has been changed
and change is permanant as it should be.
but when calling to setframe3, i am passing just pointer , not its address
setframe3(tp);
and in setframe3 , tp->data has been changed
and change is permanant here too , why??
why??
i mean i am not passing address of pointer
so why changes made are permanant, not local .