#include <iostream>
using namespace std;
int m_value = 1;
void func(int *p){
p = &m_value;
*p = m_value;
}
void func1(int &p){
p = m_value;
cout << &p << endl;
}
void func2(int **p){
**p = m_value;
cout << 3233333333 << **p << endl;
}
void func3(int *p){
*p = m_value;
}
int main(int argc, char *argv[]){
int n = 2;
int *pn = &n;
*pn += 2;
cout << 100000 << pn << endl;
cout << 2 << pn << endl;
cout << 3 << *pn << endl;
cout << 4 << n << endl;
cout << 5 << pn << endl;
func(pn);
cout << 6 << *pn << endl;
func(&n);
cout << 6 << *pn << endl;
func3(&n);
cout << 6 << *pn << endl;
cout << 600 << n << endl;
func1(*pn);
cout << 7 << *pn << endl;
func1(n);
cout << 8 << *pn << endl;
cout << 9 << &*pn << endl;
*pn = 5;
cout << 10 << *pn << endl;
func2(&pn);
cout << 11 << n << endl;
return 0;
}
c++,指针:只有用&传参才会改变实际变量的值
最新推荐文章于 2024-06-10 08:21:17 发布