#include<stdio.h>
void sq(int &b) {
b=b+12;
}
void main() {
int a=5;
sq(a);
printf("%d",a);
}
In the above c program, it does not work but the same works in c++ i.e.
#include<iostream>
void sq(int &b) {
b=b+12;
}
int main() {
int a=5;
sq(a);
std::cout<<a;
}
Is there a difference in how the variable is passed in c++ ?? whydoes it work in c++ ?
is above code pass by reference in c++ ?
C and C++ are different languages. C does not have references.
If you want reference semantics in C, then use pointers: