A Variable Array Index - C++ Data Type

C++ examples for Data Type:Array

Description

A Variable Array Index

Demo Code

#include <iostream> 
  
using namespace std; 
  
int main(int argc, char *argv [])
{ 
        int intArray[5] = { 5, 6, 7, 8, 9 }; 
  
        unsigned int index = 0; 
        cout << "Index: " << index << endl; 
        cout << "Value: " << intArray[index++] << endl; 
  
        cout << "Index: " << index << endl; 
        cout << "Value: " << intArray[index++] << endl; 
  
        cout << "Index: " << index << endl; 
        cout << "Value: " << intArray[index++] << endl; 
  
        cout << "Index: " << index << endl; 
        cout << "Value: " << intArray[index++] << endl; 
  
        cout << "Index: " << index << endl; 
        cout << "Value: " << intArray[index++] << endl; 
        return 0; 
}

Related Tutorials