Hi
I am passing or want to pass value of a char array, so that even thoug the called routine is changing the values the calling function should not see the values changed, meaning only copy should be passed
Here is the program
#include<iostream.h>
#include<string.h>
void f(char a[]);
int main()
{
char ch[20]="This is a";
f(ch);
cout<<"\nCH= "<<ch;
In general strings and arrays are passed implicitly by reference in C/C++.
Replace void f(char a[]) with void f(char a) in your declaration and definition.
Thanks.
This is the simple approach. So passing an array (integer or character) is passing an address and hence manipulating it will reflect in the called program also.
By default function arguments are passed by value that is a copy of the original argument is passed to the function. Arrays are passed by reference that is the location of the beginning of the array is passed as an argument to the callee in order to save space in memory. To pass an array by value follow jim mcnamara's advice.