In the previous post, you learned to create simple Hello World program in C++ by using Dev-C++ editor. This tutorial teaches you the basic syntax of C++ programming language that you should know since you are new to this computer programming language.
#include <iostream> It is statement written down to include iostream header file. that will allow us to use the command to receive input from users and diplay text on the screen.
using namespace std; The statement will import std namespace and allow us to use commands without having to type out their full name. A namespece defines name of varialbe or functions so that they do not conflict with other variable or functions that have the same names.
** C++ program will start from the main method;
int main(int argc, char *argv[])
{
}
** Return 0; This statement will tell the C++ compiler that your program ends here without any error.A value other than zero will be treated as abnormal termination by the operation system.
Cout followed by <<
it is used to print text on the screen
Comments
Like other language, in C++ programming language, comments are used to explain the code written or to exclude the part of code from being excuted. There are two types of comments.
1.. // is used to make comments for a single line. you can write only a single line of text or code after the single-line comments. For a normal text, it will be used to explain or describe the code. If you place the C++ code after the comment, this code won't be compiled.
2../* */ is used to make comments for multiple lines. you can write multiple lines of text or code in the multiple-line comment block. if you place the code between /*and*/, the won't be compiled.
Example
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
/*Your first program will print the words Hello World on the screen*/
{
cout<<"Hello World\n";//Print Hellow world ont the screen
system("pause");
return 0;
}
The Result
0 comments:
Post a Comment