Code Your First C++ Program

Exercise:

Write a C++ program that displays “Hello, C++ Programming World!” onto the screen.

Click Here to View the Solution!
#include <iostream>
using namespace std;
int main()
 {
    // prints the string onto the screen
    cout << "Hello, C++ Programming World!"; 
    return 0; // exits the program
} // end of main function
Click Here to View the Output!
Hello, C++ Programming World!
Click Here to View the Explanation!
  • // is used to write comments in C++ language. These comments assist the reader of the code to read comments for a better understanding of the code. The compiler completely ignores lines that start with //
  • #include helps add libraries to the program. It is a preprocessor command. #include <iostream> indicated that the iostream library’s contents are added to the program. 
  • With the help of this, the command cout can be used in the program to display output on your screen. 
  • As a beginner, you only need to learn that the command #include <iostream> will allow you to display outputs on your screen using cout
  • For a C++ program to be valid, int main() function is essential. The curly brackets right after the main indicate the function’s beginning and end. This is the first step to executing any function in this language. 
  • std::cout << "Hello, C++ Programming World!";
    To display your content on the screen, std::cout is typed, and any text between quotation marks are printed. The format string follows << necessarily. In our program, the format string is "Hello, C++ Programming World!"
  • Also, note that the end of the statement is always marked by ;

%d bloggers like this: