+ 2
Why this program does not output "Hi there!" sentence without using main function?
#include <iostream> using namespace std; void printSomething() { cout << "Hi there!"; } int main() { printSomething(); return 0; }
5 Respuestas
+ 5
If your code compiles successfully(without any error), the compiler starts executing statements within basic main function. This is because, the compiler is programmed to start execution from the main function. So that, you have to call your own functions inside the main in order to get the output you except.
Refer to this link to know more:
https://en.cppreference.com/w/cpp/language/main_function
+ 2
All programs in C++ first Execute the main() function and execution begins with main().
It not only for C++. Most of languages start run with main().
+ 1
Vadivelan
if there is no main function in program, is it executable or not?
+ 1
+ 1
main() is used to initiate the function. So if you have many functions, the main() will be the one that controls all the other functions.
It is more of the more of the "mother" function or "head" function...