Last active
June 19, 2018 02:57
-
-
Save khanh96le/5bad6a350da340c4d4b294640d7cd842 to your computer and use it in GitHub Desktop.
C++ Pointers
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
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