讲解C++编程中Address-of运算符&的作用及用法

2020-01-06 14:23:02于丽


// expre_Address_Of_Operator3.cpp
// compile with: /EHsc
// Demonstrate address-of operator &

#include <iostream>
using namespace std;

// Function argument is pointer to type int
int square( int *n ) {
  return (*n) * (*n);
}

int main() {
  int mynum = 5;
  cout << square( &mynum ) << endl;  // pass address of int
}

Output


25


注:相关教程知识阅读请移步到C++教程频道。