S
sam pal
I have the following programs and please clear my doubts. Passing the
value by reference is same as pointer by reference. Is this true?
What is the difference between display and display2?
How can I change display1 to value by reference if there is
difference?
void display(int &i){// Passing value by reference
++i;
}
void display2(int *i){ // Pointer by reference
++(*i);
}
void display1(char *pchr){ //I want to change to Value by reference if
any difference.
cout << pchr;
strcpy(pchr,"Hello");
}
int main(){
int i =0;
int *i1=new int;
char *str = new char [20];
display(i);
cout << i << endl;
strcpy(str,"Temp");
display1(str);
cout <<"Value="<< str << endl;
*i1=0;
display2(i1);
cout << *i1 << endl;
}
value by reference is same as pointer by reference. Is this true?
What is the difference between display and display2?
How can I change display1 to value by reference if there is
difference?
void display(int &i){// Passing value by reference
++i;
}
void display2(int *i){ // Pointer by reference
++(*i);
}
void display1(char *pchr){ //I want to change to Value by reference if
any difference.
cout << pchr;
strcpy(pchr,"Hello");
}
int main(){
int i =0;
int *i1=new int;
char *str = new char [20];
display(i);
cout << i << endl;
strcpy(str,"Temp");
display1(str);
cout <<"Value="<< str << endl;
*i1=0;
display2(i1);
cout << *i1 << endl;
}