当前位置: 代码迷 >> C语言 >> 弱弱的请教一个指针做函数参数的问题?
  详细解决方案

弱弱的请教一个指针做函数参数的问题?

热度:224   发布时间:2005-09-16 19:56:00.0
弱弱的请教一个指针做函数参数的问题?
   下面的程序怎么老是出错啊?
#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  

----------------解决方案--------------------------------------------------------
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无这个限制!
----------------解决方案--------------------------------------------------------
#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);
}
帮你改了一下,已经调试过了
----------------解决方案--------------------------------------------------------
上面两种方法都调试通过了,xiexie!
----------------解决方案--------------------------------------------------------
  相关解决方案