1. #include <iostream>
  2. #include <math.h>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.  
  11.  
  12.  
  13.  
  14. // try replacing the declaration below
  15. //with this one
  16. //char x[]= {'a','b','c','d'};
  17.  
  18. //create a c string...the null terminator is automatically added
  19. char x[10] ="abcd";
  20.  
  21. for(int i=0; x[i]!= '\0';i++){
  22. cout <<"x["<<i<<"] : "<< x[i]<<endl;
  23. }
  24.  
  25. cout<<"\n-Now with a While Loop-"<<endl;
  26.  
  27. int count= 0;
  28. while(x[count] != '\0'){
  29. cout <<"x["<<count<<"] : "<< x[count++]<<endl;
  30.  
  31. }
  32.  
  33. // Try uncommenting the lines below to see what happens
  34. //x ="wxyz";
  35.  
  36. //
  37. char y[10];
  38. //char * strcpy ( char * destination, const char * source )
  39. cout<<"\n-copy x to y-"<<endl;
  40. strcpy(y,x);
  41. count=0;
  42. while(y[count] != '\0'){
  43. cout <<"y["<<count<<"] : "<< y[count++]<<endl;
  44.  
  45. }
  46.  
  47.  
  48. if(x==y)
  49. cout<<"\nThey are equal"<<endl;
  50. else
  51. cout<<"\nThey are not equal"<<endl;
  52. if(strcmp(x,y)==0)
  53. cout<<"\n strcmp(x,y) is true"<<endl;
  54. else
  55. cout<<"\nstrcmp(x,y) is false"<<endl;
  56.  
  57. }