|
|
写了个结构体的小测试,个结果发现C语言是不支持按址传递的
#include<stdio.h>#include<stdlib.h>typedef struct Str{ int i; int j;}str;int giveinfo(str &str);int main(){ str str; giveinfo(str); str.i = 89; printf("%d\n",str.i); printf("%d\n",str.j); return 0;}int giveinfo(str &str){ str.i = 9; str.j = 20; return 0;}
开始我用gcc编译 gcc -o struct struct.c
总是出现错误:
struct.c:9: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
struct.c:19: 错误:expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
怎么改都不行,后来我就用g++编译就成功了。 |
|