Vous êtes sur la page 1sur 8

WHAT IS C++?

C++ is a computer programming language created in 1983 by Bjarne Stroustrup and designed to serve as an enhanced version of the C language. It is object oriented and is considered a high level language. However, it features low level facilities. C++ is one of the most commonly used programming languages. The development of C++ actually began four years before its release, in 1979. It did not start out with this name; its first name was "C with Classes." In the late part of 1983, C with Classes was first used for AT&Ts internal programming needs. Its name was changed to C++ later in the same year. The language was not released commercially until the late part of 1985.

Developed at Bell Labs, C++ enhanced the C programming language in a variety of ways. Among its features are classes, virtual functions, templates, and operator overloading. The language also counts multiple inheritance and exception handling among its many features. C++ introduced the use of declarations as statements and includes more type checking than is available with C. Considered a superset of C, C++ maintains a variety of features that are included within its predecessor. As such, C programs are generally able to run successfully in C++ compilers, although there are some issues that may cause C code to perform differently. In fact, it is possible for some C code to be incompatible in C++. The C++ computer programming language was created for UNIX, providing programmers with the advantage of being able to modify code without actually changing it. The code is reusable. Library creation is also cleaner. The language is considered portable and does not require the use of a specific piece of hardware or just one operating system. Another important feature of C++ is the use of classes. Classes help programmers organize of their code and avoid mistakes. There are times when mistakes do slip through, but classes can be instrumental in finding bugs and correcting them. The original C++ compiler, called Cfront, was written in the C++ programming language. Compilation in this language is considered efficient and fast. Its speed can be attributed to its high-level features in conjunction with its low-level components. When compared to other computer programming languages, it can be viewed as quite short. This is due to the fact that it leans towards the use of special characters instead of keywords.

WHO IS WRITTEN C++?

Bjarne Stroustrup

DESCRIBE THE PURPOSE OF THE FOLLOWING SYNTAX ANG GRAMMAR 1. # Lines beginning with a hash sign (#) are directives for the preprocessor 2. #include This variant is used for system header files 3. Iostream.h Library lived in the headersiostream.h now CFront, its library and The C++ Programming Langauge formed the de facto standard for C++ for some time. 4. Int.main () This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. 5. Before we begin, let us first clarify the key difference between functions and procedures. A procedure is set of instructions to be executed, with no return value. A function is a procedure with a return value. For readers familiar with C/C++, a procedure is simply a function with a void return value, as in void proc_sayhello(). 6. Cout cout represents the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters. 7. << Shift left 8. Hello World\n: A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program. 9. /n New line 10. ; Notice that the statement ends with a semicolon character (;).

5 MATHEMATICAL OPERATORS AND 6 RELATIONAL OPERATORS MATHEMATICAL OPERATORS SYMBOL MEANING

Addition

Subtraction

Multiplication

Division

Modulo

RELATIONAL OPERATORS

SYMBOL

MEANING

==

Equal to

!=

Not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

STATE STATEMENT BELOW AND GIVE AN EXAMPLE APPLICATION IN C++ PROGRAM 1. Go To A statement label is meaningful only to a goto statement; in any other context, a labeled statement is executed without regard to the label. A jump-statement must reside in the same function and can appear before only one statement in the same function. The set of identifier names following a goto has its own name space so the names do not interfere with other identifiers. Labels cannot be redeclared. It is good programming style to use the break, continue, and return statement in preference to goto whenever possible. Since the break statement only exits from one level of the loop, a goto may be necessary for exiting a loop from within a deeply nested loop. EXAMPLE // goto_statement.cpp #include <stdio.h> int main() { int i, j; for ( i = 0; i < 10; i++ ) { printf_s( "Outer loop executing. i = %d\n", i ); for ( j = 0; j < 2; j++ ) { printf_s( " Inner loop executing. j = %d\n", j ); if ( i == 3 ) goto stop; } } // This message does not print: printf_s( "Loop exited. i = %d\n", i ); stop: printf_s( "Jumped to stop. i = %d\n", i ); }

2. While The test of expression takes place before each execution of the loop; therefore, a while loop executes zero or more times. expression must be of an integral type, a pointer type, or a class type with an unambiguous conversion to an integral or pointer type. A while loop can also terminate when a break, goto, or return within the statement body is executed. Use continue to terminate the current iteration without exiting the while loop. continue passes control to the next iteration of the while loop. EXAMPLE
// while_statement.cpp #include <string.h> #include <stdio.h> char *trim( char *szSource ) { char *pszEOS = 0; // Set pointer to character before terminating NULL pszEOS = szSource + strlen( szSource ) - 1; // iterate backwards until non '_' is found while( (pszEOS >= szSource) && (*pszEOS == '_') ) *pszEOS-- = '\0'; return szSource; } int main() { char szbuf[] = "12345_____"; printf_s("\nBefore trim: %s", szbuf); printf_s("\nAfter trim: %s\n", trim(szbuf)); }

3. BREAK AND CONTINUE Continue : causes a while or for loop to begin again at the top of the loop. EXAMPLE if (value > 10) goto end; if (value < 10) goto end; cout << "value is 10!"; end: cout << "done"; Break : causes the immediate end of a while or for loop. Execution jumps to the closing brace. EXAMPLE while (condition) { if (condition2) break; // statements; }

4. Do / While The test of the termination condition is made after each execution of the loop; therefore, a do-while loop executes one or more times, depending on the value of the termination expression. The do-while statement can also terminate when a break, goto, or return statement is executed within the statement body. EXAMPLE // do_while_statement.cpp #include <stdio.h> int main() { int i = 0; do { printf_s("\n%d",i++); } while (i < 3); }

5. Jump / Loop jump statement performs an immediate local transfer of control. EXAMPLE break; continue; return [expression]; goto identifier; A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages. EXAMPLE #include <iostream> using namespace std; int main () { for( ; ; ) { printf("This loop will run forever.\n"); } return 0; }

6. If / Else If the value of expression is nonzero, statement1 is executed. If the optional else is present, statement2 is executed if the value of expression is zero. expression must be of arithmetic or pointer type, or it must be of a class type that defines an unambiguous conversion to an arithmetic or pointer type. (For information about conversions, see Standard Conversions). In both forms of the if statement, expression, which can have any value except a structure, is evaluated, including all side effects. Control passes from the if statement to the next statement in the program unless one of the statements contains a break, continue, or goto. The else clause of an if...else statement is associated with the closest previous if statement in the same scope that does not have a corresponding else statement. EXAMPLE
// if_else_statement.cpp #include <stdio.h> int main() { int x = 0; if ( 1 ) // if statement #1 // { if ( !x ) // if statement #2 printf_s("!x\n"); else // paired with if statement #2 printf_s("x\n"); // } }

Vous aimerez peut-être aussi