#include <bits/stdc++.h>
using namespace std;
// Function to copy one string in to other
// using recursion
void myCopy(char str1[], char str2[], int index = 0)
{
// copying each character from s1 to s2
s2[index] = s1[index];
// if string reach to end then stop
if (s1[index] == '\0')
return;
// increase character index by one
myCopy(s1, s2, index + 1);
}
// Driver function
int main()
{
char s1[100] = "GEEKSFORGEEKS";
char s2[100] = "";
myCopy(s1, s2);
cout << s2;
return 0;
}
I did not understand how the value of s2 is getting printed ....since we passed address of s1 and s2 to function mycopy(). mycopy() has two local array str1 and str2 as argument,so i was thinking two local array with values of s1 and s2 will be created.(call by values)
Shouldn't the function prototype be mycopy(char *s1,char *s2) for printing s2.(call by reference)