#include <iostream>
using namespace std;
void add(int a, int b,int *sum){
*sum = a + b;
}
void add(int a,int b,int &sum){
sum = a + b;
}
int main(int argc, const char * argv[]) {
int sum = 0;
int a = 1;
int b = 2;
add(a, b, &sum);
cout << "指针加法运算结果:" << sum << endl;
add(a, b, sum);
cout << "引用加法运算结果:" << sum << endl;
return 0;
}
网友评论