C 库函数 - atexit()

C 语言教程 · 2019-02-24 08:29:04

描述

C 库函数 int atexit(void (*func)(void)) 当程序正常终止时,调用指定的函数 func。您可以在任何地方注册你的终止函数,但它会在程序终止的时候被调用。

声明

下面是 atexit() 函数的声明。

int atexit(void (*func)(void))

参数

  • func -- 在程序终止时被调用的函数。

返回值

如果函数成功注册,则该函数返回零,否则返回一个非零值。

实例

下面的实例演示了 atexit() 函数的用法。

#include <stdio.h>
#include <stdlib.h>

void functionA ()
{
   printf("这是函数A\n");
}

int main ()
{
   /* 注册终止函数 */
   atexit(functionA );
   
   printf("启动主程序...\n");

   printf("退出主程序...\n");

   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

启动主程序...
退出主程序...
这是函数A

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide

PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide

Larry Ullman / Peachpit Press / 2005 / USD 39.99

It hasn't taken Web developers long to discover that when it comes to creating dynamic, database-driven Web sites, MySQL and PHP provide a winning open source combination. Add this book to the mix, an......一起来看看 《PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具