Created
May 18, 2020 17:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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