Last active
January 10, 2016 02:59
-
-
Save mu-777/5840bff9ef3ebb4a9f29 to your computer and use it in GitHub Desktop.
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; | |
void val(int i) { // 値渡し | |
cout << i << endl; // 0 | |
cout << &i << endl; // 0x7ffd066ebfac | |
i = 1; | |
} | |
void ref(int &i) { // 参照渡し | |
cout << i << endl; // 0 | |
cout << &i << endl; // 0x7ffd066ebfc4 | |
i = 2; | |
} | |
void ptr(int *i) { // ポインタ渡し | |
cout << i << endl; // 0x7ffd066ebfc4 | |
cout << *i << endl; // 2 | |
*i = 3; | |
} | |
int main() { | |
// your code goes here | |
int a = 0; | |
int *p = &a; | |
cout << p << endl; // 0x7ffd066ebfc4 <- pの値=aのアドレス(=aのポインタ) | |
cout << &p << endl; // 0x7ffd066ebfc8 <- pのアドレス(=pのポインタ) | |
cout << *p << endl; // 0 <- aの値 | |
val(a); | |
cout << a << endl; // 0 | |
cout << &a << endl; // 0x7ffd066ebfc4 | |
ref(a); | |
cout << a << endl; // 2 | |
cout << &a << endl; // 0x7ffd066ebfc4 | |
ptr(&a); | |
cout << a << endl; // 3 | |
cout << &a << endl; // 0x7ffd066ebfc4 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment