void类型
void为 空类型
viod类型不可以直接定义数据;
void i=10; 不可行
void类型可以·作为函数的返回值类型 表示没有返回值
无参无返回值
void main()
{
printf("hehehe\n");
}
return;\\或无
函数声明
1)、当函数被调用时与住函数不在同一文件中时需要声明;
2)、当函数的定义在主函数之后需要声明;
3)、声明的变量不需要建立存储空间,eg:extern int a:
extern 关键词只做声明,不做定义, 即 此时的a不能被赋值
include<stdio.h>
int main()
{
extern int a;\\函数的声明
a=20;\\error,没有空间不可以被·赋值
int b=10;定义变量b,b类型为int,赋值10
}
return 0;
主函数和exit函数
在主函数(main)中调用exit和return结果是一样的,都是程序的终止,但在子函数中调用return值代表子函数终止了,跳转到执行主函数,在子函数中调用exit程序终止了。
#include<stdio.h>
#include<stdlib.h>
void fun()
{
printf("hello\n");
printf("hello\n");
printf("hello\n");
printf("hello\n");
exit(0);
printf("hello\n");
printf("hello\n");
printf("hello\n");
}
int main
{
fun();
printf("world\n");
printf("world\n");
printf("world\n");
return 0;
}
输出结果:
hello
hello
hello
hello
多文件编程
为避免同一个文件被include多次,C/C++中有两种方式,一种是#ifndef方式,一种是#pragma once方式
方法一
#ifndef_SOMEFILE_H_
#define_SOMEFILE_H_
\\声明语句
#endif
方法二
#pragma once
\\声明语句