INTRO TO C++

C++ (pronounced "see plus plus") is a statically typed, free-form, multi paradigm, compiled,
general purpose programming language. It is regarded as an intermediate-level language, as it
comprises both high-level and low level language features. Developed by Bjarne Stroustrup
starting in 1979 at Bell Labs, C++ was originally named C with Classes, adding object oriented features, such as classes, and other enhancements to the C programming language. The language was renamed C++ in 1983. C++ is one of the most popular programming languages and is implemented on a wide variety of hardware and operating system platforms. As an efficient compiler to native code, its application domains include systems software, application software, device drivers, embedded software,
high-performance server and client applications, and entertainment software such as Video
games. C++ is also used for hardware design, where the design is initially described in C++, then analyzed, architecturally constrained, and scheduled to create a register-transfer level hardware description language via high level synthesis.
The language began as enhancements to C, first adding classes, then virtual functions, operator overloading, multiple inheritance, templates and exception handling, among other features. After years of development, the C++ programming language standard was ratified in
STRUCTURE OF C++ PROGRAM
C++ uses notation that may appear strange to non programmers. Let us begin by considering a
simple program that prints a line of text.
1 // our first program in C++
2 #include <iostream>
3 using namespace std;
4 int main ()
5 {
6 cout << "Welcome to the world of C++ !\n”;
7 return 0; // the program ended successfully
8 }
Output
Welcome to the world of computer
The above program illustrates many features of C++ language. We will look at the program line
by line.
Line 1: // our first program in C++
// the two slash sign are comments and do not have any effect on the behavior of the program.
The programmer can use them to include short explanation or observations within the source
code itself. Therefore, the line is a brief description of what our program is. Another way to write
a comment is to put it between /* and */ but a comment of this form may span multiple lines.
Line 2: # include <iostream>
Lines beginning with a hash sign (#) are directives for the processor. They are not regular code
lines with expressions but indications for the compiler’s preprocessor. In this case the directive #
include <iostream> tells the preprocessor to includes in the program the iostream standard file.
Line 3: Using name space std;
All the elements of the standard C++ library are declared within what is called a namespace, the
namespace with the name std. so in order to access its functionality we declare with this
expression that we will be using these entities. This line is very frequent inC++ programs that
use the standard library.
Line 4: int main ( )
Is a part of every C++ program. The line corresponds to the beginning of the definition of the
main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it- the instruction contained within this function’s will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all c++ programs have a main function.
The word main is followed in the code by a pair of parentheses ( ( ) ). That is because it is a
function declaration: in C++, what differentiate a function declaration from other types of
expressions are these parentheses that follow its name. Optionally, these parentheses may
enclose a list of parameters within them.
Line 5 and 8: { }
Within the curly brackets is the body of the main function ( {}). What is contained within these braces is what the function does when it is executed.
Line 6: cout << “welcome to the world of C++ ! “<<endl;
This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs only action that generates a visible effect in our program.Cout is the name of the standard output stream in C++, it instructs the computer to print on the screen the strings of characters contained between quotation marks. The semicolon is a statement terminator; every statement must end with a semicolon.
Line 7: return 0;
The return statement causes the main function to finish.
Other information
The operator << is referred to as the stream insertion operator. When this program executes, the value to the right of the operator, the right operand, is inserted in the output stream. The characters of the right operand normally print exactly as they appear between the double quotes.Notice however, that the characters \n are not printed on the screen. The backslash (\) is called an escape character. It indicates that “a special” character is to be output. When a backslash is
encountered in a string of characters, the next character is combined with the backslash to form an escape sequence. The escape sequence\n means newline. It causes the cursor (i.e the current screen position indicator) to move to the beginning of the next line on the screen. Some other common escape sequences are listed below.
Escape
Sequence
Description
\n Newline. Position the screen to the beginning of the next line.
// Forward slash. Used to insert comment inside program
\\ Backslash. Used
\r Carriage return. Position the screen cursor to the beginning of the current line;
do not advance to the next line.
\t Horizontal tab. Move the screen cursor to the next tab stop.
\a Alert. Sound the system bell
\” Double quote. Used to print double quite character
.
Share on Google Plus

About Unknown

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment