Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Program to Test Array Initializations

% cat arrayTest.cpp
// test array features
#include<iostream>
using namespace std;

int main()
{
  const int NUM_EL = 5;
  int i;

  // too few numbers in initialization list
  int scores[NUM_EL] = {97};

  // too many numbers
  //int scores[NUM_EL] = {97, 82, 57, 98, 88, 99, 100};

  cout << scores[4] << endl;

  // out-of-bounds assignment
  // scores[1000] = 55;

  return 0;
}
% g++ arrayTest.cpp
% a.out
0

 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming