

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C/C++ difference's between "int main()" and "int main(void)"
C
In C programming language, if a function signature is not having any parameters then it can take multiple arguments as input but the same is not true with C++. The compilation will fail if arguments are passed to such a function in C++. This is reason int main() and int main(void) are same in C, but int main(void) is better approach, which restricts the user to pass multiple arguments to main function.
Example (C)
#include <stdio.h> int main() { static int counter = 3; if (--counter){ printf("%d ", counter); main(5); } }
Output
2 1
Example (C++)
#include <iostream> using namespace std; int main() { static int counter = 3; if (--counter){ cout << counter; main(5); } }
Output
main.cpp: In function 'int main()': main.cpp:10:13: error: too many arguments to function 'int main()' main(5); ^ main.cpp:5:5: note: declared here int main() ^~~~
- Related Questions & Answers
- What's the difference between "STL" and "C++ Standard Library"?
- Difference between void main and int main in C/C++
- What's the difference between "!!" and "?" in Kotlin?
- Differentiate between int main and int main(void) function in C
- What's the difference between "update" and "update_idletasks" in Tkinter?
- Difference between “int main()” and “int main(void)” in C/C++?
- Difference between "new operator" and "operator new" in C++?
- Difference between "." and "#" selector in CSS
- Difference between "fold" and "reduce" in Kotlin
- Difference between "*" and "Any" in Kotlin generics
- What is the difference between "std::endl" and "\n" in C++?
- Equality checks in Kotlin (Difference between "==" and "===" Operators)
- Difference between "grid" and "pack" geometry managers in Tkinter
- Difference between a "class" and an "object" in Kotlin
- Difference between "fill" and "expand" options for tkinter pack method
Advertisements