Tuesday, October 13, 2015

Is main() function a built-in function or user defined function ?

This question “Is main () function a built-in function or a user defined function…? can be considered analogous to the hypothetical question as whether an egg is first or a hen…!!! The reasons for the persistence of this kind of a chaos is brought-out in the following section.
The main () function as a built-in function:
  1. The compilers of most of the programming languages are so designed that the main () function constitutes the entry point of the program execution. It defines the point from which the program has to start executing itself though there are many other sub-routines and other user-defined functions included in the program.
  2. The main () function is the controlling section of our code because even though the control of the program is shifted to the UDF (user defined function) during the program execution after a function-call from main (), once it's execution is completed, the control is transferred back to the main () function with some or no return value (as in the case of a void function).
  3. The main () function provides a platform for calling the first user-defined function in the program.
  4. It has got its own functionality and structural features with respect to the usage of syntaxes which cannot be changed by the end user unless he writes his own compiler. But the UDF's have functions and structures designed by the user or programmer.
  5. The main () has function definition (the code of a function) but it doesn't have any function declaration. Though we often use int main () or void main (), these declarations are not compulsory. But a UDF should have such declarations.
The main () function as a User-defined function:
  • The main characteristic of the UDF's is that the function definition is entirely given by the programmer and it's also true that in every program we write; the code inside the main () function is absolutely different from the other. If at all it was a built-in function then the source code in the main () function would have remained the same in all the programs.
  • The main () function is never declared in any other sub-routine before calling it and this gave a rise to what is called as the scope of variables and functions as 'local' and 'global', which is undoubtedly a user defined and user-wished context. Rather main () function acts as a reference section for the user to define a local or a global variable/function.
  • The main () function can also be sent with arguments while it's execution like that of a UDF which are referred to as formal parameters or dummy parameters.
The conclusion that can be drawn is that even though main () function is undoubtedly a built-in function, it cannot rule out the fact that, it also satisfies all the conditions and constraints of a user defined function. With respect to the instant of time and context of usage we can go on referring it to as built-in function or user-defined function interchangeably.

No comments:

Post a Comment