954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Address of a 2D array.......

0x241f8e0 0x241f8e4 0X241f8e8 0x241f8ec 0x241f8f0
0x241f8f4 0x241f8f8 0x241f8fc 0x241f900 0x241f904

After printing adress of a 2D Array of size 2x5... this is the out-put printed...can someone help mi with explaining the trend.....Is it something like printing consecutive memory blocks??? please help mi out of my confusion..... thanks in advance for your help...

haven_u
Light Poster
36 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

It's printing the address of where it was stored in the computer.

Say you had an array called x, and you wanted to print out x[0]. Right now, you are telling it to print out the address of where x[0] was stored on your computer. What you really want is it to print out the value.

If you post up your code, I can help you find the error.

DemonGal711
Junior Poster
190 posts since Apr 2008
Reputation Points: 18
Solved Threads: 10
 

I think that you are using pointers and you are printing the pointer and not its content.

For example, you may be doing this:

int* a = new int(5);
cout << a; //This prints 0xsomething...
cout << *a; //This prints 5
delete a;

Maybe you should do:

cout << (*(*array[i])[j]);

Or just:

cout << **array[i][j];

Or just a * on front of what you want to print is necessary.

That's the beauty and the shame of C++: the syntax!

GDICommander
Posting Whiz in Training
211 posts since Jun 2008
Reputation Points: 72
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You