Any program source has to identify a memory location as the start of the program. The OS transfers control to this point of the program or module.
In case of C programs, the starting module is NOT your program, but another initialisation routine, which has name lis c0s.obj, c0l.obj etc. This routine after doing initial housekeeping work, like storing program name, arguments, environment variables etc. in the stack, calls a routine by name main.
How else are we going to tell the OS where to start ?
At the end of executing the main() function, the control goes back to the routine from which the main was called and then to OS, which terminates the program.
main function is the function which comes under user defined function through which we can execute a program .That means without main function we cann't execute a programThough main function is the user defined function but it has the highest priority to execute a program.But we can execute a function without main by using the macro #pragma
The global main() function defines the entry point of the application. Typically, the main() function is used to parse command line switches and pass control to an appropriate function which will eventually return control to the main() function. When we exit the main() function, the program terminates. The program can also be terminated by invoking either the abort() or exit() functions from within any function. This is usually done when an unrecoverable error is encountered.
The main function defines the entry point of your C program. That is, when you execute your program, control is passed to the main function. Every C program must have one (and only one) entry point. When the main function terminates the program itself ends.
The main function has the following protocols:
int main (void);
int main (int argc, const char* argv[]);
int main (int argc, const wchar_t* argv[]);
Where:
argc - argument count
argv - argument value(s)
If you do not require command line arguments, use the first protocol, otherwise use the second. If you require wide characters (UNICODE environments), use the third version.
When using command-line arguments, the argv argument represents an array of pointers to null-terminated strings where argv[argc] is a null pointer (NULL). Also, the first argument (argv[0]) is always the fully-qualified path to the executable. Thus if you invoked the following command:
notepad /P "my file.txt"
The arguments will be as follows:
argc = 3
argv[0] = "c:\windows\notepad.exe"
argv[1] = "/P"
argv[2] = "my file.txt"
argv[3] = NULL
Note that the command-line parser uses whitespace to delimit each argument unless the argument is enclosed in double quotes.
The main function must return an integer (int) even if your operating does not use it. Although you can return void rather than an int, your code will not be portable.
The return value is typically used to indicate an error condition where the value zero indicates no error.
Windows does not use the return value, however you can still test the return value by testing the ERRORLEVEL from a command script or batch file:
@ECHO OFF
foo.exe IF ERRORLEVEL 2 GOTO Level2
IF ERRORLEVEL 1 GOTO Level1
EXIT
:Level1
ECHO The program terminated with error 1
EXIT
:Level2
ECHO The program terminated with error 2
EXIT
Note that error levels must be tested in reverse order because ERRORLEVEL 1 really means ERRORLEVEL>=1 rather than ERRORLEVEL=1 as you might (reasonably) expect.
main function consists all the library functions and headers which are used while writing the code
The main function is the function that holds all the code that runs the program (the code that controls what we see in the program)
It is an entry point function, which is the first user-defined function to be called when your program runs.
The main function is where the program begins. It should have a return type, int, to check for failure or success.
No. At minimum, you need to provide a main() function.
Nothing, it is a security hole. Use 'fgets' instead.
The c language does not have template functions. That is a c++ thing.
Actually, it is:int main (void)orint main (int, char **)the point where the execution of the program begins
The execution of the program starts with function main, wherever it is in the source.
No, it should be int type or void.
Because if you donot use main function in c program, the compiler willnot execute the program.C compiler starts execution from main function itself.
It start with function - main()
No. At minimum, you need to provide a main() function.
Yes
To specify the return-type of the function.
You can use the pow() function in math.h.
It's called 'main' by tradition; this feature lets the linker to know, where to start the execution.
The main function defines the entry point of an application in C.
it returns nothing
You cannot have a function named else, because it is a reserved word.
Use the atoi() or atol() function.