Difference between "array" and "&array"

They both are resulting in same address but they are different types of addresses.
Basically, “array” is a “pointer to the first element of array” but “&array” is a “pointer to whole array of 5 int”.

Example:

int array[5];
cout << "array        = " << array        << " : &array        = " << &array << endl; 
cout << "array + 1 = " << array + 1 << " : &array + 1 = " << &array + 1;

// output:
// array        = 0x7ffc6ab5daa0 : &array        = 0x7ffc6ab5daa0
// array + 1 = 0x7ffc6ab5daa4 : &array + 1 = 0x7ffc6ab5dab4
posted @ 2023-02-02 10:19  shendawei  阅读(26)  评论(0)    收藏  举报