SIMPLE C++ PROGRAMS
Suppose we would like to display the massage “My name is
Komputer, Many greetings to you” on the video screen.
#include <iostream.h>
void main ( ) / /
program heading
{ /
/ begin
count
<< “My name is Komputer, Many greetings to you”;
} /
/ end
The function main ( ) must be placed before the begin
statement. It invokes other functions to perform its job. The { symbol or
notation is used as the begin statement. The declaration of variables and the
type of operations are placed after begin statement. The end statement is
denoted by the symbol ‘}’. In C++, the
semicolon (;) serves the perpose of a
statement terminator rather then a separator.
Statement are terminated by a semicolon and are grouped
within braces {…}. Most statements
contain expression, sequences of operators, function calls, variable and
constants that specify computation.
Variable and function names are of arbitrary lengths and
consist of upper and lower case letters, digits and underscore and they may not
start with a numeral. All C++ keywords are written in lowercase letters.
Any statement or function within comments are not executable
and they are ignored by the compiler. The comments are specified in the
following way.
The declaration of the comment statement in the old C style
is
/ * this is a test * /
Type any alphanumeric character or statement or function
inside the back-slash followed by the symbol
* (multiplication operator) and
should be repeated for termination.
/* this is a test
program by ravic
computer */
The above alphanumeric characters will be ignored by the
compiler and is treated as a comment line or remark statement.
/*
void maim ( )
{
cout <<
“ this is a simple test \”;
{
*/
Any executable statement will also be treated as a comment
if it is followed by and terminated by the characters / * and * /
respectively. The following is the procedure for declaring comments in C++
style.
The comments may appear anywhere and should
begin with the comment delimiter / /.
For example,
/ / this is a test
/ / this is a new C++ style of
remark statement
There are two
advantages of using the comment statement. One, it is easy to understand the
variables used in the source program and the other is that it helps in
debugging or in tracing the variable by other users.
The skeleton of a
typical C++ program structure is given below:
program heading
begin
type or variable
declaration
statement of operation
results
end
The symbol back-slash (\) followed by a lower case n is used for line feed or a
new line. In C++, it is considered as a single character. For Example,
\n stands for newline or line feed
A program without using a new line character in the cout
stream statement is
#include <iostream.h>
void main (void)
{
cout
<< “ My name is Komputer “;
cout << “ Many
greethings to you “;
}
Output of the above
program
My name is Komputer Many greetings to you
c programming with samples
ReplyDeletec code | Circle Through Three Points