Prev | Next |
I expect you to know C++ already. We will go through features of C++ relatively quickly.
History |
---|
Through the 1960s, and into the early 1970s, operating systems were written in assembler language. The C programming language was originally developed as a language to replace assembler in systems programming. It was very successful, making system code portable and easier to write and read. C began to grow in popularity not just for systems programming, but as a general purpose programming language. Today C is one of the most used programming languages. The C programmer must realize, however, that C was designed to replace assembler language, and that in several important ways, it retains a very low level view of the machine. This language summary will discuss, among other things. some of the low level characteristics of C. The C++ programming language was designed as a higher level version of C, providing support for object-oriented programming. C++ retains almost all of C, however, and therefore is a mixture of low level and high level features. Often, the programmer has a choice of using low level or high level approaches. C++ was developed for about two decades before it was standardized in the late 1990s. ANSI Standard C++ is the language that we will use. |
Form and case |
---|
C and C++ are both case sensitive. That means that B and b are two different letters. If you write int x;you have declared a variable x of type int. If you write Int x;you probably get a compile error, unless you have created a type called Int. C and C++ are free-form. That is, in most contexts the end of a line is just like a space. So there is no special meaning to a line. Typically, you put one statement per line, because it looks nicer than packing several to a line, or breaking a statement into several lines. Long statements are usually placed on several lines, however. |
Comments |
---|
You can write comments in either C style or C++ style (in C++ programs). A C style comment begins with /* and ends with */. A C++ style comments begins with // and ends at the end of a line. (So C++ comments are one of the few violations of free-formness.) For example, /* Here is a C-style comment */ // Here is a C++ style comment. |
Names and reserved words |
---|
You can name things in C/C++ with names that begin with a letter or underscore, and contain letters, underscores and digits in any combination. For example, apostrophe the_list horse43 xare all names that can be given to things. Names cannot contain spaces. You should avoid names that begin with an underscore, since they are often used to name special things in the system. Certain words are special in the language, and you cannot use them to name things. |
Expressions and statements |
---|
An expression computes a value. For example, expression 3+5 has value 8. A statement is executed for an effect. For example, statement n = 1; puts value 1 into variable n. In C/C++, an expression can both compute a value and have an effect. When an expression has an effect, that effect is called a side-effect. For example, if variable n has value 5, then expression n++ has value 5, but also has the side-effect of setting n to 6. In C/C++, any expression can be a statement. So, for example, n++ is an expression, but you can write it as a statement: n++;Writing a semicolon after an expression makes it a statement. When an expression is used as a statement, the expression is computed, but its value is ignored. You can create one large statement, called a compound statement, from several smaller ones by enclosing the statements in {...}. For example, { n++; m++; }is a compound statement. The statements in the compound statement are executed in the order in which they are written. |
Simple data types | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Variables and assignment | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Prev | Next |