473,434 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Help with 2-D arrays

yue219
7
Language: C++
Im having a little trouble with understanding how to print an 2-D array. I need to print a 4x3 grid. How come i cant print out the array by typing in
Expand|Select|Wrap|Line Numbers
  1. cout << Grid << endl;
Everytime i do, i get the number 0012FF1C.
Here is the code that I wrote:

Expand|Select|Wrap|Line Numbers
  1.            .
  2.            .       
  3.            .
  4.         const int Row = 4;
  5.     const int Column = 3;
  6.  
  7.     int Grid[Row][Column];
  8.     Grid[0][0] = 1;
  9.     Grid[0][1] = 2;
  10.     Grid[0][2] = 2;
  11.     Grid[1][0] = 3;
  12.     Grid[1][1] = 1;
  13.     Grid[1][2] = 4;
  14.     Grid[2][0] = 5;
  15.     Grid[2][1] = 3;
  16.     Grid[2][2] = 4;
  17.     Grid[3][0] = 5;
  18.     Grid[3][1] = 6;
  19.     Grid[3][2] = 6;
  20.  
  21.         cout << Grid << endl;
  22.  
Oct 10 '07 #1
5 1210
try this
Expand|Select|Wrap|Line Numbers
  1.  
  2.         const int Row = 4;
  3.     const int Column = 3;
  4.         int i,j;
  5.  
  6.     int Grid[Row][Column];
  7.     Grid[0][0] = 1;
  8.     Grid[0][1] = 2;
  9.     Grid[0][2] = 2;
  10.     Grid[1][0] = 3;
  11.     Grid[1][1] = 1;
  12.     Grid[1][2] = 4;
  13.     Grid[2][0] = 5;
  14.     Grid[2][1] = 3;
  15.     Grid[2][2] = 4;
  16.     Grid[3][0] = 5;
  17.     Grid[3][1] = 6;
  18.     Grid[3][2] = 6;
  19.  
  20. for (i=0;i<4;i+)
  21. {
  22.     for(j=0;j<3;j++)
  23.     {
  24.         cout << Grid [i][j]<< endl;
  25.     }
  26. }
  27.  

might they useful to u.

Mayur
Oct 10 '07 #2
yue219
7
try this
Expand|Select|Wrap|Line Numbers
  1.  
  2.         const int Row = 4;
  3.     const int Column = 3;
  4.         int i,j;
  5.  
  6.     int Grid[Row][Column];
  7.     Grid[0][0] = 1;
  8.     Grid[0][1] = 2;
  9.     Grid[0][2] = 2;
  10.     Grid[1][0] = 3;
  11.     Grid[1][1] = 1;
  12.     Grid[1][2] = 4;
  13.     Grid[2][0] = 5;
  14.     Grid[2][1] = 3;
  15.     Grid[2][2] = 4;
  16.     Grid[3][0] = 5;
  17.     Grid[3][1] = 6;
  18.     Grid[3][2] = 6;
  19.  
  20. for (i=0;i<4;i+)
  21. {
  22.     for(j=0;j<3;j++)
  23.     {
  24.         cout << Grid [i][j]<< endl;
  25.     }
  26. }
  27.  

might they useful to u.

Mayur

Ah, thank you. Hummm... but what is the purpose of a for loop? Could i also use a "while" and "if" loop?
Oct 10 '07 #3
sicarie
4,677 Expert Mod 4TB
Ah, thank you. Hummm... but what is the purpose of a for loop? Could i also use a "while" and "if" loop?
You could, but there is no good reason to do that.

Have a look at an explanation of control structures (aka loops).
Oct 10 '07 #4
yue219
7
You could, but there is no good reason to do that.

Have a look at an explanation of control structures (aka loops).
Thank you, thank you =]
Oct 10 '07 #5
sicarie
4,677 Expert Mod 4TB
Absolutely. That link includes code examples, so you'll learn a lot by playing around with it. Breaking it and fixing it again.

And please, feel free to post again if you get stuck.
Oct 10 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dariusz | last post by:
I want to use arrays in my website (flat file for a guestbook), but despite having read through countless online tutorials on the topic, I just can't get my code to work. I know there are...
4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
4
by: Mingus Tsai | last post by:
Hello- please help with unpickling problem: I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows XPhome system. My problem is with using cPickle to deserialize my pickled...
8
by: inkexit | last post by:
I am a very amatuer c++ programmer and a somewhat accomplished composer. I am trying to write some code that creates 'self similar' melodies from a base melody the user inputs. This musical idea...
1
by: Geoff | last post by:
I was wondering if anyone could help me with a problem I am having. I am trying to read in a list of numbers from a file and then sort them using pointers and malloc() and free(). I know how to...
2
by: Pasacco | last post by:
dear I want to ask help on this problem. Array a is partitioned into a0 and a1 in main(). Then a1 is partitioned into a2 and a3 in th_partition() function. And I think this problem is something...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
2
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I...
5
by: saytri | last post by:
Hi i have this project were i have to do a quiz. i wrote the questions in a textfile and i called them through java. I have also made a menu to choose which type of quiz. But before accessing the...
110
by: fjm | last post by:
For some reason, I have always had a hard time understanding arrays as they pertain to php and databases. I understand associative arrays just fine but when there are multidimensional arrays, I kinda...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.