C++ Syntax
Displaying “Hello World! ,Welcome to OPH” is usually the first step to learn about the syntax of a programming language.
For Example: C++ program to display "Hello World! Welcome to OPH"
File Name: main.cpp
Output:
Explaining Example
First line of Code : #include iostream is the header file which contains all the functions of program like cout, cin etc. and #include tells the preprocessor to include these header file in the program.
Second line of Code : The using namespace std; statement just means that in the scope it is present, make all the things under the std namespace available without having to prefix std:: before each of them.
Third line of Code : A blank line. C++ ignores white space. But we use it to make the code more readable.
Fourth line of Code : main() {. . . .} A valid C++ program must have the main() function. The curly braces indicate the start and the end of the function.
The execution of code beings from this function.
Fifth line of Code: cout<<“Hello World! Welcome to OPH”; This line tells the compiler to display the message “Hello World! Welcome to OPH ” on the screen. This line is called a statement in C++. Every statement is meant to perform some task. A semi-colon ‘;’ is used to end a statement. Semi-colon character at the end of the statement is used to indicate that the statement is ending there. The std::cout is used to identify the standard character output device which is usually the desktop screen. Everything followed by the character “<<” is displayed to the output device.
Sixth line of code : return 0; This is also a statement. This statement is used to return a value from a function and indicates the finishing of a function. This statement is basically used in functions to return the results of the operations performed by a function.