Introduction to Arrays

An array is a data structure which allows a collective name to be given to a group of elements which all have the same type. An individual element of an array is identified by its own unique index or subscript. An array can be thought of as a collection of numbered boxes each containing one data item.

Simple code for an array:

#include<iostream.h>
#include<conio.h>
void main()
{
       char name[20];
       int length=0;
       clrscr();

       cout<<"\n\t Enter name: ";        
       cin>>name;
 
       while(name[length]!='\0')
       {
             cout<<"\n\t"<<name[length];
             length++;
       }
       getch();
}

Bibliography:
https://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node176.html

Advertisements

One thought on “Introduction to Arrays

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s