int y= 10;
int x[] = {42, 651, 10};
pointer(&y, x);
void pointer(int *yPtr, int *xPtr2)
{
cout << *yPtr; // shows value
cout << yPtr; // shows adress
cout << *xPtr; // shows x[0] value
cout << xPtr; // shows x[0] adress
cout << xPtr[2]; // shows xPtr[2] value ?! wut ?!
// wasnt supposed to show the adress of xPtr[2]?
// if i try *xPtr[2] to get the value of xPtr[2] i get errors
// can you guys explain me in detail how it works?
}
Did you even attempt to read the information at the links? Those links EXPLAIN what you need to know. From the second link:
An array is an array and a pointer is a pointer, but in most cases array names are converted to pointers. A term often used is that they decay to pointers.
#include <iostream>
int main()
{
int x[] { 42, 651, 10 }; // type of 'x' is 'array of 3 int'
int* p = x ; // implicit conversion from array to pointer.
std::cout << p << '\n' // address of first element of 'x'
<< p+1 << '\n' // address of second element of 'x'
<< x << '\n' // address of first element of 'x' (implicit conversion from array to pointer)
<< x+1 << '\n' // address of second element of 'x' (implicit conversion from array to pointer)
<< *p << '\n' // first element of 'x'
<< *(p+0) << '\n' // same as above
<< *(p+1) << '\n' // second element of 'x'
<< p[0] << '\n' // same as *(p+0)
<< p[1] << '\n' // same as *(p+1)
<< x[0] << '\n' // same as *(x+0) same as *(p+0) (implicit conversion from array to pointer)
<< x[1] << '\n' ; // same as *(x+1) same as *(p+1) (implicit conversion from array to pointer)
}