21-11-2012, 01:02 PM
The C++ Language
1The C++ Language.ppt (Size: 85 KB / Downloads: 128)
C is Alive in C++
C++ is a superset of C.
Any correct C program is also a correct C++ program, except for some loopholes in C that are not allowed in C++.
What is still the same
The syntax of statements
if-else, switch, the “?:” conditional
for/while/do-while loops
assignments
arithmetic/logic/relational/ bitwise expressions
declarations, struct/union/enum types, typedef
pointers, arrays,
casting
Same preprocessor commands in C &C++.
C++: A Better C
Convenient syntax for inline comments: // …
Declaration anywhere
Function overloading
Default arguments
Simplified IO: cin >>, cout<<, and more
A new Boolean data type: bool
Easier dynamic memory allocation: new & delete
References (automatically dereferenced pointers)
Function templates: data types as parameters
Tag names as new data types
Better type system: tighter use of void *
Declaration Anywhere
Declarations need no longer be at the head of blocks.
Variables and functions can be declared any time, anywhere in a program, preferably as close to where a variable is used the first time.
For example: note i is declared within for
Simplified IO
Instead of the complicated syntax of printf and scanf, and the many variations of print and scan, C++ offers a much simpler syntax
For standard output, use cout
For standard input, use cin
File IO is also simpler, and will be discussed later
Note: one can still use the IO syntax of C in C++