六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 98|回复: 0

原来C语言是不支持引用传递的

[复制链接]

升级  58%

7

主题

7

主题

7

主题

童生

Rank: 1

积分
29
 楼主| 发表于 2013-1-27 04:47:23 | 显示全部楼层 |阅读模式
写了个结构体的小测试,个结果发现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++编译就成功了。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表