3. Prepared By: Asst. Prof. Sejal Jadav
• main() function is the entry point of any C++ program.
• It is the point at which execution of program is started.
• When a C++ program is executed, the execution control goes
directly to the main() function.
• Every C++ program have a main() function.
1. The main function
4. Prepared By: Asst. Prof. Sejal Jadav
Syntax
main() [OR int main()]
{
//body of program
return 0; //optional
}
• In the above syntax …..
5. Prepared By: Asst. Prof. Sejal Jadav
int :
• This is perfectly valid because the main() doesn’t return any
value to the operating system.
• In C++, by default, the main() returns int type value to the
operating system.
• Thus the function returning a value should have return
statement for termination.
6. Prepared By: Asst. Prof. Sejal Jadav
• Here int keyword in the main() function declaration is
optional.
• If return statement at the end is missing, most compilers
will generate the warning that the function should return a
value.
7. Prepared By: Asst. Prof. Sejal Jadav
main:
• is a name of function which is predefined function in C++
library.
• Note: In the turbo C compiler the main() should include
void keyword as if it is not returning any value even in C –
language program. Above explanation is perfect for ANSI
compilers.
8. Prepared By: Asst. Prof. Sejal Jadav
Program:
#include<iostream.h>
main() //by default it returns an int type value.
{
cout<< “College of Computer, Science & Information
Technology – Junagadh”;
return 0;
// return statement is necessary otherwise warning is there
}
9. Prepared By: Asst. Prof. Sejal Jadav
2. What is Function prototype?
• A function prototype or function interface is a declaration of
a function that specifies the function's name and type
signature (data types of parameters, and return type), but
omits the function body.
• Function Declaration is also known as Function Prototype
• Functions need to be declared before use (just like variable)
• Function can be declared locally or globally
• Function has a name, return type and arguments.
10. Prepared By: Asst. Prof. Sejal Jadav
Syntax:
<return_type><function_name> (<argument_list>);
11. Prepared By: Asst. Prof. Sejal Jadav
• The argument list contains the types and names of argument
that must be passed to function.
• each argument variable must be declared independently.
• float volume (int x, float y, float z);
• But combination like float volume(int x, float y, z); is not
allowed.
12. Prepared By: Asst. Prof. Sejal Jadav
Function declaration & function calling :