cpp_bas - IEG4180 Network Software Design and Programming...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
IEG4180 Network Software Design and Programming Supplementary Notes on C++ Programming Part I - Language Basics
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 2 Copyright Jack Y.B. Lee 0. Contents • 1. What is C++ • 2. Types and Declarations • 3. Functions • 4. Memory Management • 5. Exception • 6. Source Files and Programs
Background image of page 2
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 3 Copyright Jack Y.B. Lee 1. What is C++? • A general-purpose programming language with bias towards system programming . • A better C that ± supports data abstraction , ± supports object-oriented programming , and ± supports generic programming . •A N S I S t a n d a r d C + + ± Language definition ± Standard Template Library (STL) • written entirely in C++
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 4 Copyright Jack Y.B. Lee 2. Types and Declarations • Fundamental Types ± A Boolean type ( bool ) ± Character types ( char , etc.) ± Integer types ( short , int , long , etc.) ± Floating-point types ( float , double , etc.) ± void ± Enumeration types ( enum ) • Type variations ± Pointer types ( int * ) ± Array types ( char [] ) ± Reference types ( int & ) ± Data structures and classes new new new improved
Background image of page 4
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 5 Copyright Jack Y.B. Lee 2. Types and Declarations • New and Improved Types ± Boolean Type ± Multibyte Characters • To support languages such as Chinese, Japanese, etc. • However, encoding is implementation specific. (e.g. Unicode, BIG5, etc.) bool b = true; bool c = b == false; // normal char char c; // Type c = 'A'; // Literals // normal char wchar_t c; // Type c = L'ab'; // Literals
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 6 Copyright Jack Y.B. Lee 2. Types and Declarations • Declarations v.s. Definitions ± Declaration tells the compiler the type of an identifier . ± Definition tells the compiler the entity an identifier actually refers to. ± Examples: • Declaration only: • Declaration with definition: int sqr(int x); extern int x; struct Point; int sqr(int x) { return x*x; } int x; struct Point { int x, y; };
Background image of page 6
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 7 Copyright Jack Y.B. Lee 2. Types and Declarations • Scope ± The range of program segment where an identifier is defined. ± Example: int x; // global x void f() { int x; // local x hides global x x = 1; // assigns to local x { int x; // hides the first local x x = 2; // assigns to second local x } x = 3; // assigns to first local x ::x = 4; // assigns to global x }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
IEG4180 : Supplementary Notes on C++ Programming - Part 1: Language Basics 8 Copyright Jack Y.B. Lee 2. Types and Declarations • Initialization ± A variable's value can be initialized at definition. ± Example: ± Good Style: • One common programming mistake is forgetting to initialize variable before use: •S o , always initialize your variable whenever possible during definition.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 53

cpp_bas - IEG4180 Network Software Design and Programming...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online