C++ char arrays Store and initialize

Description

C++ char arrays Store and initialize

#include <iostream>
using namespace std;
#include <string.h>
int main()//from w w w  .  j  a va  2s. co  m
{
   // Declare all arrays and initialize the first one.
   char friend1[20] = "this is a test";
   char friend2[20];
   char friend3[20];
   // Use a function to initialize the second array.
   strcpy(friend2, "another test");
   friend3[0] = 'A';  // Initialize the last,
   friend3[1] = 'd';  // an element at a time.
   friend3[2] = 'a';
   friend3[3] = 'm';
   friend3[4] = ' ';
   friend3[5] = 'G';
   friend3[6] = '.';
   friend3[7] = '1';
   friend3[8] = '2';
   friend3[9] = '3';
   friend3[10] = 'i';
   friend3[11] = 't';
   friend3[12] = 'h';
   friend3[13] = '\0';
   // Print all three names.
   cout << friend1 << "\n";
   cout << friend2 << "\n";
   cout << friend3 << "\n";
   return 0;
}



PreviousNext

Related