0 0
Read Time:1 Minute, 19 Second


C++ Hello World Program

Here’s a simple “Hello, World!” program in C++:

#include <iostream>
using namespace std;

int main() {
   cout<<"Hello, World!"<<endl;
  return 0;
}

Let’s break down what’s happening here:

  1. The first line #include <iostream> is a preprocessor directive that tells the compiler to include the iostream library. This library provides input/output functionality, such as printing output to the console.
  2. The int main() function is the entry point of the program. This is where the program starts executing.
  3. The line std::cout << "Hello, World!" << std::endl; prints the text “Hello, World!” to the console. The << operator is used to write data to the console, and std::endl is used to insert a newline character after the text.
  4. The return 0; statement ends the main function and returns the value 0 to the operating system. A return value of 0 indicates that the program executed successfully.

To run this program, you will need a C++ compiler installed on your system. Once you have a compiler installed, save the code above in a file with a .cpp extension (for example, helloworld.cpp). Then, open a terminal or command prompt, navigate to the directory where the file is saved, and enter the following command to compile the program:

g++ helloworld.cpp -o helloworld

This will compile the program and generate an executable file called “helloworld”. To run the program, enter the following command:

./helloworld

This will execute the program and print the message “Hello, World!” to the console.



Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %