Initializing an array in a declaration. - C++ Data Type

C++ examples for Data Type:Array

Description

Initializing an array in a declaration.

Demo Code

#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() /*from  w  ww  .j  a  v a 2 s .com*/
{ 
    // use initializer list to initialize array n 
    int n[ 10 ] = { 2, 7, 4, 8, 5, 4, 0, 7, 60, 37 }; 

    cout << "Element" << setw( 13 ) << "Value" << endl; 

    // output each array element's value 
    for ( int i = 0; i < 10; ++i ) 
        cout << setw( 7 ) << i << setw( 13 ) << n[ i ] << endl; 
}

Result


Related Tutorials