您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> C语言 >> 辅导 >> 正文    
  奇怪的返回:ask:ask 【注册男护士专用博客】          

奇怪的返回:ask:ask

www.nanhushi.com     佚名   不详 

  test.h请看:

  linux# gcc test1.c

  linux# ./a.out

  -1073743380

  linux# cat test1.c

  #include <test.h>

  main()

  {

  int a=2,b;

  b=pri(a);

  printf("%d\n",b);

  }

  linux# cat /usr/include/test.h

  pri()

  {int x;

  return x;

  }

  linux#

  我就只是返回了x 怎么会打印出一个奇怪的数  我的要求是只返回x的值。

  pri()

  ???

  return pro()

  什么类型。。。。。

  pri() /* 应该有返回值 如: int pri(int a)

  {int x; /* 这个x没有初始化,值是不一定的 */

  return x;

  }

  而且,你把test.h放在/usr/include下面实在是奇怪,应该放在test.c同一目录下,在test.c里用 #include "test.h" 包含这个文件

  另外,一般 .h 文件是不包含函数定义的,只有函数声明

  不知道你正在学C语言的哪一部分,在试验什么特性

  如果没有指定的话

  c中默认表示返回int值
  
  学到了函数,我看见/usr/include/*里文件全是英文的,我就想自已写个试试有同样的效果吗?

  要返回X的值 在同一目录下写3个文件,
  test.h

  代码:
  #ifndef TEST_H#define TEST_Hint pri(int);#endif /* TEST_H */

  test.c

  代码:

  #include "test.h"intpri(int a){  return(a * 2);}

  main.c

  代码:
  #include <stdio.h>#include "test.h"intmain(void){  int x;  x = pri(5);  printf("x = %d\n", x);  exit(0);}

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目