Question:
What whould we the main function of C++?
Rustam
2010-01-06 01:28:01 UTC
What whould we the main function of C++?
Five answers:
2010-01-09 23:54:39 UTC
In C, if you don't return anything...it will show a warning message that functiona should return a value and then it will return a int type containing a 0 by default....coz zero is the signal to OS that program terminated normally i.e. without any critical errors...



Free Website Templates http://www.stylishtemplate.com
?
2010-01-06 10:26:15 UTC
In C++, the function prototype of the main function looks like one of the following:



int main(void)



int main(int argc, char *argv[])



The parameters argc, argument count, and argv, argument vector, respectively give the number and value of the program's command-line arguments. The names of argc and argv may be any valid identifier in C, but it is common convention to use these names. In C++, the names are to be taken literally, and the "void" in the parameter list is to be omitted, if strict conformance is desired . Other platform-dependent formats are also allowed by the C and C++ standards, except that in C++ the return type must stay int; for example, Unix (though not POSIX.1) and Microsoft Visual C++ have a third argument giving the program's environment, otherwise accessible through getenv in stdlib.h:



int main(int argc, char **argv, char **envp)



Mac OSX and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:



int main(int argc, char **argv, char **envp, char **apple)



The value returned from the main function becomes the exit status of the process, though the C standard only ascribes specific meaning to two values: EXIT_SUCCESS (traditionally zero) and EXIT_FAILURE. The meaning of other possible return values is implementation-defined.

By convention, the command-line arguments specified by argc and argv include the name of the program as the first element; if a user types a command of "rm file", the shell will initialise the rm process with argc = 2 and argv = ["rm", "file"]. As argv[0] is the name that processes appear under in ps,top etc., some programs, such as daemons or those running within an interpreter or virtual machine (where argv[0] would be the name of the host executable), may choose to alter their argv to give a more descriptive argv[0], usually by means of the exec system call.



The main function is special; normally every C and C++ program must define it exactly once, with that name.

main must be declared as if it has external linkage; it cannot be declared static.



In C++, main must be in the global namespace (i.e. ::main) and cannot be a (class or instance)member function , although the name is not reserved, and may be used for other (ordinary) member functions or non-member functions.
?
2010-01-07 05:05:40 UTC
main() function is the place where a program starts. It is also the heart of any programming language.
2010-01-06 09:57:33 UTC
int wmain()

{

//when use the unicode characters

}



int main()

{

//without the unicode characters

}



when program executes all codes inside main function executes first it doesn't matter there are lot of codes above main function
?
2010-01-06 09:36:40 UTC
Your question makes no sense. Can you clarify ?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...