When you say
i never declared any function pointer for atexit function in this code i just passed the function name, you are correct. You didn't declare atexit. Nonetheless atexit was declared.
In this case, atexit is declared in stdlib.h and I suspect stdlib.h was #included in conio.h.
OK, so now I think you mean how to declare a function the same as the built in functions. The answer is to declare your function in a header file and then #include the header in your own program.
To do this first create your header file:
MyHeader.h:
- int Nagaharish(void (*fc)(void));
-
Then in your program:
- #include "MyHeader.h"
-
-
void f(){
-
printf("hi");
-
}
-
-
int main()
-
{
-
Nagaharish(f);
-
}
Finally, in a separate .c file code your function:
- int Nagaharish(void (*fp)(void))
-
{
-
fp();
-
return 0;
-
}
-
You now compile both the program .c file and the file with your function. The two files are linked together after each is compiled. The linked file is your .exe.
This is usually accomplished in your compiler tool by creating a project with the two .c files in it and then building the project.
Does this help?