1 / / program02.cpp
2 # include <iostream.h>
3 void main ()
4 {
5 court <<"Hi. Congratulations to learn C + +";
6}
The program above can we save with the name "program02.cpp".
Function main ()
C + + programs can not be separated from the function because the function is one of the constituent basic blocks in C + +. A minimum of C + + program contains a function that is the function main ().
This function is the beginning and end of the C + + program execution. main title is the name of the function. Starting from {sign up} is called the body's functions, or any sign which is located inside the {} is called a block.
Sign () is used to enclose the function argument, ie the value to be passed to the function. The word that precedes void main () is used to declare that this function has no return value (return value). In the sign of {} can be contained a number of units called the statement (statement).
statement
Note the line of code below:
1 court <<"Hi. Congratulations to learn C + + ";
Line is a statement that is used to display text that is located on a pair of double quotes to the screen. Writing which is located on a pair of double quotation marks are called strings. Each statement must end with a semicolon (;).
Know the court
Court is an object identifier that is provided by C + + to direct the data to standard output (normally the screen). Signs <<operator is an operator called "insertion / placement".
1 court <<"Hi. Congratulations to learn C + + ";
This operator directs operand (data) that his right to object dikirinya. In the above example, the string "Hi. Congratulations to learn C + + "is directed to the court which gave the appearance of the string to the screen.
# Include <iostream>
Line is not a statement, which is why not end with a semicolon. These lines instruct the compiler to insert other files (iostream.h) when the program is compiled. The files ending in. H called the header files, ie files that contain various declarations such as functions, variables, etc..
In the example, the file iostream.h should be included in programs that involve the object court. Because the file iostream.h contains declarations required by the court and various objects associated with the input and output on the stream.
clrscr ()
Statement clrscr () is used to clean the screen. If using the statement, then the following lines should be included:1 # include <conio.h>
Examples of the use clrscr ():1 / / program03.cpp2 # include <iostream.h>3 # include <conio.h>45 void main ()6 {7 clrscr ();8 court <<"Hi. Congratulations to learn C + +";9}
Style of Writing Program
C + + programmers to give freedom to form or style of writing programs. Example:1 / / program04.cpp2 # include <iostream.h>3 # include <conio.h>45 void main () {clrscr (); court <<"Hi. Congratulations to learn C + +";}
Comment
Comments are an important part in a program.Comments can be:
The purpose / function of the program
When the program created or revised
Other explanations about the usefulness of a number of statements in the program.
In C + + comments begin with two slash marks (//). This is used to comment on one line. In addition, comments can also be preceded by / * and ends with * /. This is used to comment that consists of several lines.1 / / a comment2 / / this is a comment34 / * this is a comment5 which can be used for multiple lines6 is the end of comment * /
0 komentar: On The development of C + + Programming Language
Posting Komentar