CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

HELP...new to C++, help with arrays topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2007, 12:29 AM
Junior Member
 
Join Date: Dec 2007
Location: Illinois
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
styles8687 is on a distinguished road
Send a message via AIM to styles8687 Send a message via Yahoo to styles8687
| More
Red face HELP...new to C++, help with arrays

if ur willing to help me understand one and multi-dimensional arrays plz reply to my email. styles8687@yahoo.com
Reply With Quote
  #2  
Old 07-25-2008, 05:04 AM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: HELP...new to C++, help with arrays

It doesn't work that way; this isn't 1-1.

A one dimensional array is a list of items.
int i[10]; declares an array of 10 ints which are accessed as i[0] through i[9].
An example of a 1D array is a set of coordinates, for example int i[3] can store x,y and z components of a point in 3D space.

A two dimensional array is a list of arrays.
int i[10][10]; declares an array of 10 arrays of 10 ints which are accessed as i[0][0] through i[0][9], i[1][0] through i[1][9] and so on.
If you're writing a program to play chess you might use a 2D array.

An n-dimensional array simply extends the above to as many dimensions as you want, for example a five dimensional array would be int i[10][10][10][10][10];.

Clear?
Reply With Quote
  #3  
Old 11-29-2008, 08:28 PM
Junior Member
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mutantkeyboard is on a distinguished road
| More
Re: HELP...new to C++, help with arrays

well man you have many tutorials on array theme
as xpiotos has already said... array is just bunch of elements of some type put on one place...
and as I saw xpiotos has also mentioned that calculation is starting from zero so it means array of 10 elements is going 0,1,2,3,4,5,6,7,8,9 if there would be 10 it would be 11 element array
because every array contains N-1 numbers in itself...
int x[5] allocates 5 elements of type integer
someclassorstructname x[10] defines 10 elements of your own type
same with pointers
int *x = new int[5];
this is dinamicaly allocated array of five elements
Reply With Quote
  #4  
Old 12-02-2008, 05:34 AM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: HELP...new to C++, help with arrays

Quote:
Originally Posted by mutantkeyboard View Post
because every array contains N-1 numbers in itself...
Not quite. N-1 is the maximum index, but if you define int x[N] then it will contain N numbers. int x[3] defines three elements, x[0], x[1] and x[2].
Reply With Quote
  #5  
Old 12-12-2008, 12:50 AM
Member
 
Join Date: Dec 2008
Posts: 48
Thanks: 0
Thanked 1 Time in 1 Post
hkp819 is on a distinguished road
| More
Re: HELP...new to C++, help with arrays

What is a Multidimensional Array?

A Multidimensional array is an array of arrays.

How are Multidimensional Arrays represented in C++
int Exforsys[3][4];
int Exforsys[3][4][2];

it is possible to handle multidimensional arrays of any number of rows and columns in C++ programming language. This is all occupied in memory. Better utilization of memory must also be made.

Multidimensional Array Example:

Code:
#include <iostream.h>
const int ROW=4;
const int COLUMN =3;
void main()
{
   int i,j;
   int Exforsys[ROW][COLUMN];
   for(i=0;i<ROWS;i++)
   for(j=0;j<COLUMN;J++)
   {
   cout << "Enter value of Row "<<i+1;
   cout<<",Column "<<j+1<<":";
   cin>>Exforsys[i][j];
   }
   cout<<"\n\n\n";
   cout<< " COLUMN\n";
   cout<< " 1 2 3";
   for(i=0;i<ROW;i++)
   {
   cout<<"\nROW "<<i+1;
   for(j=0;j<COLUMN;J++)
   cout<<Exforsys[i][j];
}


The output of the above program is

Enter value of Row 1, Column 1:10
Enter value of Row 1, Column 2:20
Enter value of Row 1, Column 3:30
Enter value of Row 2, Column 1:40
Enter value of Row 2, Column 2:50
Enter value of Row 2, Column 3:60
Enter value of Row 3, Column 1:70
Enter value of Row 3, Column 2:80
Enter value of Row 3, Column 3:90
Enter value of Row 4, Column 1:100
Enter value of Row 4, Column 2:110
Enter value of Row 4, Column 3:120

COLUMN
1 2 3
ROW 1 10 20 30
ROW 2 40 50 60
ROW 3 70 80 90
ROW 4 100 110 120

.................................................. .............

Last edited by shabbir; 12-12-2008 at 03:00 AM. Reason: Code block
Reply With Quote
  #6  
Old 03-18-2011, 03:16 PM
jsh jsh is offline
Junior Member
 
Join Date: Mar 2011
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
jsh is on a distinguished road
| More
Re: HELP...new to C++, help with arrays

Code:
#include<iostream.h>
#include<conio.h>
#define ROW 4;
#define COLUMN 3;

void main()
{
  clrscr();
  int i,j,k;
  int Exforsys[ROW][COLUMN];
  cout<<".::Enter New Array::..\n";
  for (i=0;i<ROW;i++)
    for(j=0;j<COLUMN;j++)
       {
          gotoxy(5+(i*4),5+(j*2));
          cin>>Exforsys[i][j];
      }
   k=j+2;
   cout<<"\n---------\n";
   for (i=0;i<ROW;i++)
    for(j=0;j<COLUMN;j++)
       {
          gotoxy(5+(i*4),k+(j*2));
          cout<<Exforsys[i][j];
      }
}

1 10 20 30
2 40 50 60
3 70 80 90
4 100 110 120
-----------
1 10 20 30
2 40 50 60
3 70 80 90
4 100 110 120
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing arrays in C# Xarzu C# Programming 3 09-29-2008 05:27 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:14 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board