多文件函数调用

//函数调用
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ void print_my_name();//函数声明 ,尽量每个函数都要声明,养成好习惯 int main(int argc, char *argv[]) { printf_my_name();//调用子函数 return 0; } //子函数定义 void printf_my_name() { printf("kinson"); }


//多文件函数调用
/*
------------主函数---------------- 
 调用其他文件的函数 
*/

#include "b.h"//把自己写的头文件包含进来 


int main() 
{
    int ans = sum(2,2); //调用其他文件的函数
    printf("%d",ans); 
    return 0;
}

 

/*
------主函数与子函数之间链接的桥梁------ 
*/ 
#ifndef _B_h_//固定格式,文件名大写
#define _B_H_//固定格式,文件名大写

int sum(int x,int y);//函数声明

#endif//固定格式 

 

 

 


/*
-----------子函数-------------- 
*/ 
#include "b.h"//包含头文件

//头文件中声明的函数具体实现
int sum(int x,int y)
{
    return x*y;
} 

 



 

posted @ 2017-05-08 19:31  徐景祥  阅读(525)  评论(0编辑  收藏  举报