- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the proper declaration of main in C++?
The main() function is a global function. It is used to start the execution of program. Every program should have main(). The command line arguments argc and argv are optional.
The standard prototype of main() function is as follows.
int main() { body } OR int main(int argc, char *argv[]) { body }
Here,
argc − Number of arguments passed to the program from the environment where program runs.
argv − pointer to the first element of an array.
The following is an example of main()
Example
#include <iostream> using namespace std; int sum(int x, int y) { int s = x + y; cout << "The sum of numbers : " << s; } int main() { sum(28, 8); return 0; }
Output
The sum of numbers : 36
In the above program, the code is present in sum() to calculate the sum of two numbers.
int sum(int x, int y) { int s = x + y; cout << "The sum of numbers : " << s; }
The main() function is invoking function sum()
sum(28, 8);
Advertisements