Passing by value a char array

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;

}
void f(char b[])
{
b[0]='A';
cout<<b;

}

$ ./a.out
Ahis is a
CH= Ahis is a$

Is there any thing wrong i am doing?

REgards
rkraj

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.

Regards

But still i will not be able to pass the copy of my array. I can pass only one character. When i pass the array it implicilty passes the address.

Regards
rkraj

Another approach is to copy the string to temporary storage in the function.

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.

Regards
rkraj

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.