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://codercto.com/courses/l/17.html

查看所有标签

Two Scoops of Django

Two Scoops of Django

Daniel Greenfeld、Audrey M. Roy / CreateSpace Independent Publishing Platform / 2013-4-16 / USD 29.95

Two Scoops of Django: Best Practices For Django 1.5 is chock-full of material that will help you with your Django projects. We'll introduce you to various tips, tricks, patterns, code snippets, and......一起来看看 《Two Scoops of Django》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换