What’s the matter with Dev-C++, or are there errors in my code about using reference variable?
#include <stdio.h>
struct P {
int x;
};
int main(int argc, char **argv){
struct P Point[5];
struct P & rPoint;
int i;
for(i=0;i<=4;i++) {
rPoint = Point[i]; // I know. I can use Point[i].x = i. But...
rPoint.x = i;
}
for(i=0;i<=4;i++) {
rPoint = Point[i];
printf("%d\n", rPoint.x);
}
system("pause");
return 0;
}
Error: 9 C:***\main.c syntax error before ‘&’ token
C++ does not allow unassigned references, so this is your error:
If you want reassignment, use a pointer.