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 IConceptA function is user-defined when the programmer supplies its definition in the program. A pre-defined or library function is supplied by the language…

  1. A.

    Only I

  2. B.

    Only II

  3. C.

    Both I and II

  4. 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

  1. A hosted C++ program provides a function named main() at global scope.

  2. The programmer writes the definition and body of main() in the source program.

  3. The C++ implementation gives this programmer-defined function its special role: program execution begins by invoking main().

  4. 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.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…