Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DalyaG/8ff35c7781141851bb1dff7b715217ec to your computer and use it in GitHub Desktop.
Save DalyaG/8ff35c7781141851bb1dff7b715217ec to your computer and use it in GitHub Desktop.
Pointers and references in C++: An Array is a Pointer to an Alias
#include <iostream>
using namespace std;
int main() {
int arr[5];
arr[0] = 1;
cout << "arr[0]=" << arr[0] << endl;
*arr = 2;
cout << "arr[0]=" << arr[0] << endl;
int *ip = arr;
*ip = 3;
cout << "arr[0]=" << arr[0] << endl;
++ip;
*ip = 4;
cout << "arr[1]=" << arr[1] << endl;
*(++ip) = 5;
cout << "arr[2]=" << arr[2] << endl;
cout << "ip=" << ip << ", *ip=" << *ip << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment