AllFreePapers.com - All Free Papers and Essays for All Students
Search

C++ Case

Autor:   •  October 4, 2013  •  Essay  •  410 Words (2 Pages)  •  806 Views

Page 1 of 2

Here is a simple version of main does nothing but return a value:

int main() {

return 0; }

The operating system uses the value returned by main to determine whether the program succeeded or failed. A return value of 0 indicates success.

The main function is special in various ways, the most important of which are that the function must exist in every C++ program and it is the (only) function that the operating system explicitly calls.

We define main the same way we define other functions. A function definition specifies four elements: the return type, the function name, a (possibly empty) parameter list enclosed in parentheses, and the function body. The main function may have only a restricted set of parameters. As defined here, the parameter list is empty; Section 7.2.6 (p. 243) will cover the other parameters that can be defined for main.

The main function is required to have a return type of int, which is the type that represents integers. The int type is a built-in type, which means that the type is defined by the language.

{ return 0; } The only statement in our program is a return, which is a statement that terminates a function.

Note the semicolon at the end of the return statement. Semicolons mark the end of most statements in C++. They are easy to overlook, but when forgotten can lead to mysterious compiler error messages.When the return includes a value such as 0, that value is the return value of the function. The value returned must have the same type as the return type of the function or be a type that can be converted to that type. In the case of main the return type must be int, and the value 0 is an int. On most systems, the return value from main is a status indicator. A return value of 0 indicates

...

Download as:   txt (2 Kb)   pdf (53.6 Kb)   docx (10.3 Kb)  
Continue for 1 more page »