C++ hello world program

This is the very basic C++ programming to print hello world. In this guide we will print hello world using different way using C++ language. You can also take an overview to print hello world using C as well as print hello world using C++ to learn everything about printing hello world. Now, let’s print hello world using very basic concept in C++.

Print hello world using string

In this C++ program we will print hello world using string. We can print direct string or store a string to a character array and then print that array. Let’s see the program bellow.

// hello world program in C++

#include <iostream>
using namespace std;

int main(){

    cout << "Hello World" << endl;

    char helloWorld[] = "Hello world";
    cout << helloWorld << endl;    // hello world from string variable

    return 0;
}

Output of hello world program

hello-world-in-c-program-to-print-hello-world

Hello world using a class

In this bellow program we will use a class named print_hello  and then an object named hello_obj to print hello world on the screen. See the program bellow.

// hello world program using class in c++

#include<iostream>
using namespace std;

class print_hello{    // class creation
  public:

    void hello_printer(){
      cout << "Hello World" << endl;
    }
};

int main(){
    print_hello hello_obj;    // Create an object named hello_obj
    hello_obj.hello_printer();  // Call hello_printer function

    return 0;
}

Program output:

Hello World

Previous pageC++ programming

Next pageAdd two numbers