C++ Programming with Design Patterns Revealed

Chapter 2

Procedural Programming

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: Preview

Basic concepts that are similar in both Java and C++, including: ? standard data types ? control structures ? I/O ? functions

Dynamic memory management, and some basic pointer operations.

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: Main function

Java

C++

Comments about

C++

class C { public static void

main(String args[]) {

... }

int main() { ... return 0;

}

The main function is not included in any class.

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: Comments

Comments about C++

/* ...

*/ //

C++ does not provide the Java comment /** ... */, used to create documentation

Remember about programming guidelines!

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: Primitive Data Types

Comments about C++

char

char is one byte long and does not use Unicode

short int long float double

The language does not define the size and range of numeric primitive data types, which are implementation dependent. There are no predefined wrapper classes for primitive data types.

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: More Primitive Data Types

Java

C++

Comments about C++

byte

--

similar to unsigned char

boolean bool

Any non-zero numeric value can be treated as true, a zero value can be treated as false

String

string To use strings you must include the library

string language = "C" + "++";

bool mark = language < "Java";

char first = language[0];

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: typedef and sizeof

A synonym for an existing type: typedef bool Boolean;

Size of data type (in bytes): int k = 5;

... sizeof(int)... sizeof k ...

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

2: Variables, Constants and Expressions

Java

C++

final const --

const int LINES = 25;

Comma operator, e.g. e1, e2

for(i = 1, j = 2; i < N && j < M; ++i, ++j) ...

C++ Programming with Design Patterns Revealed

Tomasz M?ldner

Copyright: Addison-Wesley Publishing Company, 2002

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download