test.h請看:
linux# gcc test1.c
linux# ./a.out
-1073743380
linux# cat test1.c
#include
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 怎么會打印出一個奇怪的數(shù) 我的要求是只返回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 文件是不包含函數(shù)定義的,只有函數(shù)聲明
不知道你正在學C語言的哪一部分,在試驗什么特性
如果沒有指定的話
c中默認表示返回int值
學到了函數(shù),我看見/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#include "test.h"intmain(void){ int x; x = pri(5); printf("x = %d\n", x); exit(0);}
linux# gcc test1.c
linux# ./a.out
-1073743380
linux# cat test1.c
#include
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 怎么會打印出一個奇怪的數(shù) 我的要求是只返回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 文件是不包含函數(shù)定義的,只有函數(shù)聲明
不知道你正在學C語言的哪一部分,在試驗什么特性
如果沒有指定的話
c中默認表示返回int值
學到了函數(shù),我看見/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