top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to print "Hello C++" with empty main() in C++? Without using class.

+1 vote
90 views
How to print "Hello C++" with empty main() in C++? Without using class.
posted Jul 18, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
  • Define a class and in the constructor print "Hello C++"
  • Instantiate the class at the time of the definition so that it executes before the main.

Sample code

#include <iostream>
using namespace std;

class MyClass
{
        public:
                MyClass()
                {
                        cout << "Hello C++";
                }
} myclass;

int main()
{

}
answer Jul 19, 2017 by Salil Agrawal
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...