C++ Program to Copy Strings

#include <iostream>
using namespace std;
int main() {
   char str1[100] = "Magic";
   char str2[100];
   int i;
   for(i = 0; str1[i] != '\0'; i++)
   str2[i] = str1[i];
   str2[i] = '\0';
   cout<<"The contents of str2 are: "<<str2;
   return 0;
}

OUTPUT:

The contents of str2 are: Magic

Leave a Comment