c:函数的声明

VC6.0环境

文件1.c

#include <stdio.h>

void func_otherSourceFile()
{
	printf("this function is written in a file where some functions are located\n");
}

文件2.c

#include <stdio.h>

//在这里声明的函数在整个文件范围内有效,声明一次之后,本文件中所有函数都可以调用被声明的函数
void pub_Moduale();
void func_otherSourceFile();

int main(int argc,char*argv[])
{
	int func_withMain(char*);//声明子函数:在这里声明的函数只在主调函数范围内有效!
		
	func_withMain("hi,你好啊!");
	pub_Moduale();//在main函数之前已经声明过了,全文件有效。
	
    func_otherSourceFile();//这个函数是定义在另外一个文件里面的
	
	return 0;
}

int func_withMain(char*msg)
{	
	func_otherSourceFile();

	printf("this function is written within the source file where main() is located\n");
	printf("传入的数据是:%s\n",msg);
	
	pub_Moduale();//全文件有效函数的一个调用例子。

	return 0;
}

void pub_Moduale()
{
	func_otherSourceFile();
	printf("我是一个公共模块!\n");
}

运行结果:

this function is written in a file where some functions are located
this function is written within the source file where main() is located
传入的数据是:hi,你好啊!
this function is written in a file where some functions are located
我是一个公共模块!
this function is written in a file where some functions are located
我是一个公共模块!
this function is written in a file where some functions are located
Press any key to continue

 

转载于:https://my.oschina.net/avatus/blog/1358974

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值