Index a pointer as if it were an array. : Pointer Array « Pointer « C++






Index a pointer as if it were an array.

Index a pointer as if it were an array.
 

#include <iostream> 
#include <cctype> 
using namespace std; 
 
int main() 
{ 
  char *p; 
  int i; 
  char str[80] = "This Is A Test"; 
 
  cout << "Original string: " << str << endl; 
 
  p = str;                           // assign p the address of the start of the array 
 
  
  for(i = 0; p[i]; i++) {            // index p 
    if(isupper(p[i])) 
      p[i] = tolower(p[i]); 
    else if(islower(p[i])) 
      p[i] = toupper(p[i]); 
  } 
 
  cout << "Inverted-case string: " << str; 
 
  return 0; 
}



           
         
  








Related examples in the same category

1.The Array Name as a Constant PointerThe Array Name as a Constant Pointer
2.Using a Variable Pointer to Point to an ArrayUsing a Variable Pointer to Point to an Array
3.The name of the array is a constant pointerThe name of the array is a constant pointer
4.Incrementing a PointerIncrementing a Pointer
5.Comparing Pointer AddressesComparing Pointer Addresses
6.using array name as a constant pointer