Skip to content

Instantly share code, notes, and snippets.

@RodEsp
Last active October 4, 2019 13:10
Show Gist options
  • Save RodEsp/5817ed1a71e735c5ff6a20e1a669cd7e to your computer and use it in GitHub Desktop.
Save RodEsp/5817ed1a71e735c5ff6a20e1a669cd7e to your computer and use it in GitHub Desktop.
#include <iostream>
void func (int n, int &nA) {
std::cout << "void func (int n, int &nA) {\n";
std::cout << "----------------------------\n";
std::cout << "n " << n << "\n";
std::cout << "&n " << &n << "\n";
std::cout << "nA " << nA << "\n";
std::cout << "&nA " << &nA << "\n";
std::cout << "\n";
}
int main() {
int num = 200;
std::cout << "int num = 200;\n";
std::cout << "--------------\n";
std::cout << "num " << num << "\n";
std::cout << "&num " << &num << "\n";
std::cout << "\n";
int &numA = num;
std::cout << "int &numA = num; <-- alias, exactly the same as 'num'\n";
std::cout << "----------------\n";
std::cout << "numA " << numA << "\n";
std::cout << "&numA " << &numA << "\n";
std::cout << "\n";
int *numP = &num;
std::cout << "int *numP = &num; <-- pointer\n";
std::cout << "-----------------\n";
std::cout << "numP " << numP << "\n";
std::cout << "&numP " << &numP << " <-- address of where the pointer variable itself is stored\n";
std::cout << "*numP " << *numP << " <-- dereferenced pointer\n";
std::cout << "\n";
std::cout << "func(num, num);\n";
func(num, num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment