Thursday, December 13, 2012
C++ TUTORIAL FOR BEGINNERS: How to display characters on the screen
Objective: Displaying characters on the screen
Directive: #include <iostream>
Namespace: std
Function: main
Statements: cout, return
Output:
This is a simple C++ program.
It will display these characters on the screen.
C++ source code:
/*
PROGRAM 1: Displaying characters on the screen
AUTHOR: eternaltreasures
DATE: 2010 August 25
*/
#include <iostream>
using namespace std;
int main ()
{
cout << "This is a simple C++ program.\n";
cout << "It will display these characters on the screen.";
return 0;
}
// End of the program.
Explanations:
/*
Block of comments about the program, author, date...
*/
#include <iostream>
Preprocessor command to include the iostream file to be used for input-output operations.
using namespace std;
The contents of the namespace called std would be used. A namespace is a "container" for elements of standard C++ library.
semicolon ;
A semicolon separates statements.
int main ()
This is where the program begins to execute.
braces { }
The main function executes anything that is enclosed within these braces.
cout << "This is a simple C++ program.\n";
The cout is a statement for displaying on the screen the characters within the quotes "".
\n is for starting a new line.
return 0;
The return statement ends the execution of the main function.
0 return code means the execution is OK.
// End of the program.
A single line of comment uses two forward slashes.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment