#include<stdio.h>
void sq(int &b) {
b=b+12;
}
void main() {
int a=5;
sq(a);
printf("%d",a);
}
在上面的 c 程序中,它不起作用,但在 c++ 中同样有效,即
#include<iostream>
void sq(int &b) {
b=b+12;
}
int main() {
int a=5;
sq(a);
std::cout<<a;
}
变量在 c++ 中的传递方式有什么不同吗?为什么它在 c++ 中工作?上面的代码是在 c++ 中通过引用传递的吗?