C HISTORY BCPL developed in 1967 by Martin
C++ HISTORY BCPL developed in 1967 by Martin Richards Used as a language to write operating systems B developed about the same time by Ken Thompson Both were typeless languages ● ● ● Every data item occupied one "word" in memory and the programmer was responsible for treating the word as a real number or an integer!
C++ HISTORY (cont. ) C evloved from B by Dennis Ritchie at Bell Labs and was first implemented in 1972. Added typing and other features. Widely known as the development language for UNIX. Late 70's C had evolved into ● ● ● ● Traditional C Classic C Kernighan and Ritchie C
C++ HISTORY (cont. ) ● ● 1978 publication of "The C Programming Language" by Kernighan & Ritchie. One of the most successful computer science books of all time. Many hardware variations led to many versions of C, a SERIOUS problem. 1983 X 3 J 11 committee under American National Standars Committee on Computers & Information Processing
C++ HISTORY (cont. ) 1989 C standard was approved ANSI/ISO collaborated to standardize it world-wide in 1990 (ANSI/ISO 9899) 2 nd edition of K&R 1988 reflected this new standard. C++, an extension to C, was developed by Bjarne Stroustrup in early 1980's at Bell Labs. ● ● ● "spruce up" the C language Provide capabilities for object-oriented
A SMALL C++ PROGRAM // a small C++ program #include <iostream> using namespace std; int main(void) { cout << "Hello world!" << endl; return 0; }
// a small C++ program C++ style comments from // to end of line. /*. . . */ C style comments are also o. k. And they go for multi-lines. Another way to remove lots of lines containing both types of comments: ● ● ● ● #IFDEF RSB_01 /* other stuff, some containing comments */ Y=0; X = 12; // of either style
#include <iostream> ● ● ● Include from the standard libraries location. #include "your_local_file. h" for local header files. Watch your #includes for upcoming Standard Template Library (STL) features.
using namespace std; ● ● Removes the need to use std: : on all the std variables and functions. If ignored, and compiler complains about your first cout, then put it back in.
int main(void) ● ● Standard wants your main to return an integer for status of program (finished o. k. return 0, didn't finish o. k. , return something else. ) void added to confirm that you want no parameters from the command line.
CURLY BRACES { // all statements between a set of curly braces are // considered to be in the same unit } * for our program, they mark the statements that belong to the main function.
cout << "Hello World!" << endl; << is a binary operator left-associative ● ● ● uses as much as it can from the left and as little as it can from the right. endl is a manipulator which generates an end of line character. cout is the stream for the standard output (normally the screen). more later
return 0; ● ● Returns to the calling program, in this case the operating system, a value for the main function of 0 indicating successful completion of the program. If you discovered an error earlier in the program, you can return -1 or some other number there.
<< ● ● a binary operator left-associative cout << "Hello World!" is an expression who's value is it's left operand (in this case cout). Writing "Hello World!" on the standard output is only a SIDE EFFECT. But, it's what we want in this case.
cout << "Hello World!" << endl; ● ● ● The second << has cout << " Hello World!" as its left operand endl as its right operand. Remember the value of its left operand was cout, so this operand simply writes an additional end of line character to standard out and returns the value of cout. For now, you can simply think of the side effects and what they can do for you.
std: : cout ● ● ● a qualified name which uses the : : operator the left operand is the namespace name the right of the operand is a name that is defined in the scope named on the left. Use the using namespace to remove the need for this operator in cout, cin, endl, and other std manipulators and variables. type of cout is ostream.
STRING LITERALS ● ● ● n newline character t tab character b backspace character " treats " as a part of the string rather than the string terminator. ' treats ' as part of the string rather than a character literal terminator. \ includes in the string.
- Slides: 16