References both array and pointer using subscripts - C++ Data Type

C++ examples for Data Type:Array Pointer

Description

References both array and pointer using subscripts

Demo Code

#include <iostream>
using namespace std;
void main()/*  www  .j  av a 2  s .co  m*/
{
   float ara[] = {100.0, 200.0, 300.0, 400.0, 500.0};
   float *fptr;        
   // Make pointer point to array's first value.
   fptr = &ara[0];     
   cout << *fptr << "\n";
   fptr++;        
   cout << *fptr << "\n";   
   fptr++;        
   cout << *fptr << "\n";   
   fptr++;        
   cout << *fptr << "\n";   
   fptr++;        
   cout << *fptr << "\n";   
   fptr = ara;           
   cout << *(fptr+2) << "\n"; 

   cout << (fptr+0)[0] << " " << (ara+0)[0] << "\n";

   cout << (fptr+1)[0] << " " << (ara+1)[0] << "\n";

   cout << (fptr+4)[0] << " " << (ara+4)[0] << "\n";

   return;
}

Result


Related Tutorials