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的值。
请看:
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()
什么类型。。。。。
???
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语言的哪一部分,在试验什么特性
{int x; /* 这个x没有初始化,值是不一定的 */
return x;
}
而且,你把test.h放在/usr/include下面实在是奇怪,应该放在test.c同一目录下,在test.c里用 #include "test.h" 包含这个文件
另外,一般 .h 文件是不包含函数定义的,只有函数声明
不知道你正在学C语言的哪一部分,在试验什么特性
如果没有指定的话
c中默认表示返回int值
c中默认表示返回int值
谢谢,刷新就多了无版主的回贴了。呵呵~~~
学到了函数,我看见/usr/include/*里文件全是英文的,我就想自已写个试试有同样的效果吗?
我要返回X的值,小妹很莱,不懂怎么写。请问具体怎么写

学到了函数,我看见/usr/include/*里文件全是英文的,我就想自已写个试试有同样的效果吗?
我要返回X的值,小妹很莱,不懂怎么写。请问具体怎么写


在同一目录下写3个文件,
test.h
test.c
main.c
用 gcc main.c test.c -o test 编译
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);} |
用 gcc main.c test.c -o test 编译






