Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi all
Guide me PLZ..
Why the answer on the current code is samemain()
{
int a[5]={10,20,30,40,50};
cout>&a[0];
}
Explain the answer with the help of internal structure of Array specialy 1st element and the name of Array

An array is nothing more than a block of memory. This block of memory has a length of 5 (that's your subscript) times the sizeof(int) (which is 4). So, int a[5] is just a block of memory that is 20 bytes long. Nothing spectacular.
Ignoring the fact that your code is probably not going to do anything at all, let's look at a[3].
really, all you're getting with array subscripts is a memory location (that's all any variable is really). a[3] = a + 3 * sizeof(int) or the location of the first byte of the block of memory called a + 12 bytes. Four of these bytes are then returned. That is the integer found in the location a[3].
Unless I got this backward, your memory (starting at a) looks a bit like this:
0a 00 00 00 14 00 00 00 1e 00 00 00 28 00 00 00 32 00 00 00
The location within the data block (or whereever the compiler happened it put it) called "a" starts with the byte containing 0a. a[3] = a + 3 * sizeof(int) = a + 12 looks something like this:
V
0a 00 00 00 14 00 00 00 1e 00 00 00 28 00 00 00 32 00 00 00and returns this block of data:
0a 00 00 00 14 00 00 00 1e 00 00 00 [28 00 00 00] 32 00 00 00Now, you're using &a[0]. This is the memory address of the first element of array "a". (This is the same as saying a as a matter of fact.) &a[3] = a + 12. You're actually returning an integer value corresponding to the memory location.
It's all very simple as long as you ignore the qualifiers "int", "char", "double" etc. They really don't mean anything except 4, 1, and 8. (They do help the compiler decide which version of divide or add to use. Assembly actually has addb, addw, addd, addq and so on defining add 1 byte, add 2 bytes, add 4 bytes and add 8 bytes. Doubles and floats use the floating point instructions fdiv and so forth.)
How's that?

![]() |
Convert Dec To Hex??
|
how can be restarted !!!!
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |