Skip to content

Instantly share code, notes, and snippets.

@khanh96le
Last active June 19, 2018 02:57
Show Gist options
  • Save khanh96le/5bad6a350da340c4d4b294640d7cd842 to your computer and use it in GitHub Desktop.
Save khanh96le/5bad6a350da340c4d4b294640d7cd842 to your computer and use it in GitHub Desktop.
C++ Pointers
myvar == 25
&myvar == 1776
foo == 1776
*foo == 25
// more pointers
#include <iostream>
using namespace std;
int main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;
}
>> 10, 20, 30, 40, 50,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment