奇怪的返回:ask :ask
發表于:2007-05-26來源:作者:點擊數:
標簽:
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#
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_H
int pri(int);
#endif /* TEST_H */ |
test.c代碼:
#include "test.h"
int
pri(int a)
{
return(a * 2);
} |
main.c代碼:
#include <stdio.h>
#include "test.h"
int
main(void)
{
int x;
x = pri(5);
printf("x = %d\n", x);
exit(0);
} |
用 gcc main.c test.c -o test 編譯
原文轉自:http://www.kjueaiud.com
- 評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
-