为了账号安全,请及时绑定邮箱和手机立即绑定

C语言指针函数错误?

C语言指针函数错误?

三国纷争 2019-02-07 11:07:51
#include<stdio.h>void main(){ int a,b;a=5,b=10;printf("before swap a=%d,b=%d\n",a,b);swap(&a,&b);printf("after swap a=%d,b=%d\n",a,b);}swap( px, py){int * px,* py;int temp;temp = * px;* px = * py;* py = temp;printf("in swap x=%d,y=%d\n",* px ,* py);}运行结果时候zhizhengmain.cppF:\C语言\20130702\zhizhengmain.cpp(7) : error C2065: 'swap' : undeclared identifierF:\C语言\20130702\zhizhengmain.cpp(10) : error C2065: 'px' : undeclared identifierF:\C语言\20130702\zhizhengmain.cpp(10) : error C2065: 'py' : undeclared identifierF:\C语言\20130702\zhizhengmain.cpp(11) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition执行 cl.exe 时出错.zhizhengmain.obj - 1 error(s), 0 warning(s)为什么??
查看完整描述

3 回答

?
浮云间

TA贡献1829条经验 获得超3个赞

undeclared identifier的意思你就可以理解为没有定义。

只需要改一下就可以了。

123456789101112131415161718#include<stdio.h>void swap(int * px,int * py);//提前申明函数void main()    int a,b;    a=5,b=10;    printf("before swap a=%d,b=%d\n",a,b);    swap(&a,&b);    printf("after swap a=%d,b=%d\n",a,b);}viod swap(int * px,int * py){    int temp;    temp = * px;    * px = * py;    * py = temp;    printf("in swap x=%d,y=%d\n",* px ,* py);}


查看完整回答
反对 回复 2019-03-22
?
繁华开满天机

TA贡献1816条经验 获得超4个赞

函数swap要有类型,然后还应该在main函数前声明。。另外main函数里的swap( px, py)这里px py没有定义

查看完整回答
反对 回复 2019-03-22
  • 3 回答
  • 0 关注
  • 985 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信