rahul ummadisetti

rahul ummadisetti

  • NA
  • 47
  • 2.3k

C++ Pointer to an Array

Apr 18 2019 5:01 AM
  1. int array[]{1,31,36,65,96,65};  
  2. int * array_ptr(array);  
  3. cout << "array :" << array << endl;  
  4. cout << "&array+1 :" << &array+1 << endl;  
  5. cout << "*(&array+1) :" << *(&array+1) << endl;  
  6. cout << "(*(&array+1)-array) :" << (*(&array+1)-array) << endl;  
output :
 
array :0x7fffffffde20
&array+1 :0x7fffffffde38
*(&array+1) :0x7fffffffde38
(*(&array+1)-array) :6
*(&array+1) and &array+1 refer to the same memory location.
 
compiler throwing an exception while trying to get the size of the array using a pointer as ((&array+1) - array)
 
what is the difference between ((&array+1)-array) and (*(&array+1)-array)

Answers (2)