Home c++ Raming the pointer to the array

Raming the pointer to the array

Author

Date

Category

When smoking

std :: cout & lt; & lt; * ptr;
(or STD :: COUT & LT; & LT; PTR [0])
Shows the address.

Here the pointer is retracted into an array that disintegrates to the pointer__named element? Type pointer__name Order?

But it is unlikely, then PTR [0] +1 showed the address of the next item.

or in std :: cout & lt; & lt; ptr [0]; Array decays, and in std :: cout & lt; & lt; ptr [0] +1; Does not fall?


Answer 1, Authority 100%

In the GDB debugger, there is such a room as ptype , which shows the type of any expression. She will help us figure out:

(gdb) list
1 #Include & lt; iostream & gt;
2.
3 int Main ()
4  {
5 int array [3] = {1, 2, 3};
6 int (* PTR) [3] = & amp; array;
7.
8 std :: cout & lt; & lt; * PTR;
nine  }
(GDB) Ptype Array
Type = int [3]
(GDB) PTYPE PTR
Type = int (*) [3]
(GDB) PTYPE * PTR
Type = int [3]

It turns out that in the line

std :: cout & lt; & lt; * PTR;

* PTR – It is Array , which is implicitly converted to int [3] int * , i.e. adding to the first element of the array.


1. There is a Array-to-Pointer Decay .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions