C++ One Dimensional Array

C++ One Dimensional Array - One Dimensional Array 1...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
One Dimensional Array 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
One-dimensional array : a list of related values with the same data type, stored using a single group name (called the array name ) Syntax: dataType arrayName[number-of-items] By convention, the number of items is first declared as a constant, and the constant is used in the array declaration eg: const int size=5; int ar[size]; array elements: ar[0] ar[1] ar[2] ar[3] ar[4] 2
Background image of page 2
3 Notes: - element : an item in the array - Array storage of elements is contiguous - index (or subscript ) of an element: the position of the element within the array - Indexes always start with zero. - To reference an element, use the array name and the index of the element.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Array initialization const int size= 4; int ar [size]={1, 2, 5, 6}; // int ar[size]={4,5}; // int ar[size] = {0}; 4 1 2 5 6 4 5 0 0 0 0 0 0
Background image of page 4
Input, output, assign, and process array elements: #include<iostream> using namespace std; void main() { const int size=6; int ar[ size ]; //input: for(int i=0;i<size;i++) cin>>ar[i]; //output for(int i=0;i<size;i++)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/12/2012 for the course IT 101 taught by Professor Fadi during the Spring '12 term at University of Damascus.

Page1 / 10

C++ One Dimensional Array - One Dimensional Array 1...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online