Which statement is correct regarding the main() function in C++? I. It is a…
2021
Which statement is correct regarding the main() function in C++?
I. It is a user-defined function.
II. It is a pre-defined function.
Answer: A. Only I — ConceptA function is user-defined when the programmer supplies its definition in the program. A pre-defined or library function is supplied by the language…
- A.
Only I
- B.
Only II
- C.
Both I and II
- D.
Neither I nor II
Attempted by 1492 students.
Show answer & explanation
Correct answer: A
Concept
A function is user-defined when the programmer supplies its definition in the program. A pre-defined or library function is supplied by the language implementation or a library.
A language can reserve a function name and give that function a special role without supplying the function body itself.
Application
A hosted C++ program provides a function named main() at global scope.
The programmer writes the definition and body of main() in the source program.
The C++ implementation gives this programmer-defined function its special role: program execution begins by invoking main().
Therefore, Statement I is true and Statement II is false.
Contrast
Only I: reflects that the program supplies the definition of main().
Only II: confuses the implementation-defined entry-point role with a pre-supplied function body.
Both I and II: combines two different sources of a function definition.
Neither I nor II: overlooks that the program contains the definition of main().
Cross-check
A source program cannot merely include a standard header to obtain main(); it must define main(). Hence the result is Only I.