Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

array of charcter c++

//string using array of charcters 
#include <iostream>
#include <cstdlib>
#include <cstring>


using namespace std;

int main(){
    
  char ch1[5]={'a','b','c','d',''};     //()=NULL
  char ch2[4]="HHH";
  cout <<"ch1: " << ch1 << endl;
  cout <<"ch2: " << ch2 << endl;
  
  //copying string to another
  strcpy (ch2,ch1);
  cout <<"ch2 after strcpy: " << ch2 << endl;
  
  //concatinating 2 stringd
  strcat (ch1,ch2);
  cout <<"ch2 after strcat: " << ch1 << endl;
  
  //comparing 2 strings
  cout << strcmp("aaa","bcd");
  // prints(0) if they are equal
  // prints(1) if first < second
  // prints(-1) if second > first
  
  //getting the length of the string
  cout <<"Size of array: " << strlen (ch2);

 
}
 
PREVIOUS NEXT
Tagged: #array #charcter
ADD COMMENT
Topic
Name
1+4 =