| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 957 人关注过本帖
标题:弱弱的请教一个指针做函数参数的问题?
只看楼主 加入收藏
liebaorun
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-9-15
收藏
 问题点数:0 回复次数:3 
弱弱的请教一个指针做函数参数的问题?
   下面的程序怎么老是出错啊?
#include <stdio.h>                                                         
void swap(float *p1,float *p2)                                                
{                                                                           
  float temp;                  
  temp=*p1;*p1=*p2;*p2=temp;                                                  
}                                                                           
main()                                                                        
{                                                                           
  float a=10,b=5;                                                            
  printf("%d,%d\n",a,b);                                                      
  float *pointer_1=&a;                                                        
  float *pointer_2=&b;  
     swap(pointer_1,pointer_2);
  printf("%d,%d",a,b);
}
                                                
├────────────────────────────────── Message ───────────────────────────────────┤
│•Compiling C:\TURBOC2\C2.C:                                                   
│ Error C:\TURBOC2\C2.C 11: Expression syntax in function main                 
│ Error C:\TURBOC2\C2.C 12: Expression syntax in function main                 
│ Error C:\TURBOC2\C2.C 13: Undefined symbol 'pointer_1' in function main      
│ Error C:\TURBOC2\C2.C 13: Undefined symbol 'pointer_2' in function main      
│ Warning C:\TURBOC2\C2.C 13: Non-portable pointer conversion in function main │
│ Warning C:\TURBOC2\C2.C 13: Non-portable pointer conversion in function main │
└──────────────────────────────────────────────────────────────────────────────┘
F1-Help  F5-Zoom  F6-Switch  F7-Trace  F8-Step  F9-Make  F10-Menu   NUM


























[此贴子已经被作者于2005-9-16 20:01:35编辑过]


搜索更多相关主题的帖子: 指针 函数 参数 float temp 
2005-09-16 19:56
stnlcd
Rank: 1
等 级:新手上路
帖 子:177
专家分:1
注 册:2004-11-21
收藏
得分:0 
float a=10,b=5;                                                            
  printf("%d,%d\n",a,b);                                                      
  float *pointer_1=&a;                                                        
  float *pointer_2=&b;

改为:
 float a=10,b=5;                                                                                                               
  float *pointer_1=&a;                                                        
  float *pointer_2=&b;
  printf("%d,%d\n",a,b);   

c语言不能在定义语句中插入执行语句!!
必须在函数的最开始定义好变量!!
c++和java无这个限制!

要让一个男人破产,请给他一架相机,要让一个男人倾家荡产,请给他一架望远镜。
2005-09-16 20:27
凌云
Rank: 1
等 级:新手上路
威 望:1
帖 子:78
专家分:0
注 册:2005-9-17
收藏
得分:0 
#include <stdio.h>                                                         
void swap(float *p1,float *p2)                                                
{                                                                           
  float temp;                  
  temp=*p1;*p1=*p2;*p2=temp;                                                  
}                                                                           
void main()                                                                        
{                                                                           
  float a=10,b=5;                                                            
  printf("%.0f ,%.0f \n",a,b);                                                      
  swap(&a,&b);
  printf("%.0f ,%.0f \n",a,b);
}
帮你改了一下,已经调试过了

2005-09-17 09:47
liebaorun
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-9-15
收藏
得分:0 
上面两种方法都调试通过了,xiexie!

2005-09-17 19:14
快速回复:弱弱的请教一个指针做函数参数的问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061516 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved