Advertisement

"Hello World" Program in C++

Hello World Program in C++

Certainly! Here is a "Hello, World!" program in C++:

#include <iostream>
    int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
    }


Let me explain what each line does:

#include <iostream>


This line includes a header file called iostream, which provides input and output stream objects, such as std::cout (standard output stream) and std::cin (standard input stream).

int main()


This line declares the main function, which is the entry point of every C++ program. The main function is a special function in C++ because the operating system calls this function to start the program. The int in int main means that the main function returns an integer.

{ std::cout << "Hello, World!" << std::endl;


This line prints the string "Hello, World!" to the standard output stream std::cout. The << operator is the stream insertion operator, which inserts the string on the right into the stream on the left. The std::endl is a manipulator that inserts a newline character and flushes the stream.

return 0;


This line returns 0 from the main function. The return value of the main function is the exit status of the program, and a return value of 0 typically indicates that the program ran successfully.

}


This curly brace closes the main function.



hello world output result


Post a Comment

0 Comments