C atexit() function

C atexit() function - Processes the specified function at exit

Syntax atexit() function

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

The atexit() function is used to register the function pointed to by func, to be called without arguments at normal program termination.

Parameters atexit() function

Name Description Required /Optional
func Function to be called. Required

Return value from atexit()

  • Upon successful completion, atexit() shall return 0.
  • Otherwise, it shall return a non-zero value.

Example: atexit() function

The following example shows the usage of atexit() function.

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

void test1(void), test2(void), test3(void), test4(void);

int main( void )
   printf("From Main function....!\n");

void test1()
   printf( "Function1 \n" );

void test2()
    printf( "Function2 \n" );

void test3()
    printf( "Function3 \n" );

void test4()
    printf( "Function4 \n" );


From Main function....!

C Programming Code Editor:

Previous C Programming: C abort()
Next C Programming: C exit()

Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
    ptr = 0;// oops, I meant *ptr = 0

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q