fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a[] = {9, 8, -5};
  6. int* p = &a[2]; // p has now address of element a[2] => p is pointer to a[2]
  7.  
  8. //use *p to get the value p points to ('cout' is used to print something)
  9. cout << "element p points to " << *p << endl;
  10.  
  11. cout << "p-a = " << (p-a) << "\n";
  12. return 0;
  13. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
element p points to -5
p-a = 2