Classnote01-1x2

Classnote01-1x2 - C Primer CSE 250 Lecture Note 01 C Primer(1 Adapted from the Koffman-Wolfgang C Primer from the Instructor Materials slides by

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

View Full Document Right Arrow Icon
C++ Primer CSE 250 Lecture Note 01 C++ Primer (1) Adapted from the Koffman-Wolfgang C++ Primer, from the Instructor Materials slides by Elliot Koffman and Paul Wolfgang. This material is used by permission of John Wiley & Sons, Inc For private use only by students in CSE250 Re-distribution or public posting in any form is expressly forbidden. c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 1 / 160 Outline 1 The C++ Environment 2 Preprocessor Directives and Macros 3 C++ Control Statements 4 Primitive Data Types and Class Data Types 5 Objects, Pointers, and References 6 Functions 7 Arrays and C Strings 8 The string Class 9 Input/Output Using Streams c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 2 / 160
Background image of page 1

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

View Full DocumentRight Arrow Icon
Why C++? Compared to Java: Basic concepts, program structures are similar, (syntax differ) C++ compilers are smarter than Java compilers are allowed to be . Java provides a lots of system packages and utility classes including GUI. System support for C++ is less extensive (but still quite comprehensive). C++ has more-advanced O-O features. Most working codes are in C++, and will be for a long time. c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 3 / 160 Why C++? C++ has pointer type . When used properly, this: gives programmers more control over how objects are laid out. explicit memory management. by “packing” and assembly-level tricks. allows more-efficient code. Used improperly, the C++ code are hard to understand/debug, error-prone. Java does not have pointer type. (Actually, Java compiler uses pointer to implement class objects.) c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 4 / 160
Background image of page 2
A simple C++ program #include <iostream> #include <string> using namespace std; int main() { cout << "Enter your name\n"; string name; getline(cin, name); cout << "Hello " << name << " - welcome to C++\n"; return 0; } save this program as: HelloWorld.cpp c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 6 / 160 Compiling and Linking A C++ program consists of one or more source files. Source files contain function and class declarations and definitions . Files that contain only declarations are incorporated into the source files that need them when they are compiled. Thus they are called include files . Files that contain definitions are translated by the compiler into an intermediate form called object files . One or more object files are combined to form the executable file by the linker . c ± Xin He (University at Buffalo) CSE 250 Data Structures, Classnote01 8 / 160
Background image of page 3

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

View Full DocumentRight Arrow Icon
The #include Directive The first two lines: #include <iostream> #include <string> incorporate the declarations of the iostream and string libraries into the source code. If your program is going to use a member of the standard library , the appropriate header file must be included at the beginning of the source code file.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/31/2010 for the course EE 423 taught by Professor Mitin during the Spring '10 term at SUNY Buffalo.

Page1 / 43

Classnote01-1x2 - C Primer CSE 250 Lecture Note 01 C Primer(1 Adapted from the Koffman-Wolfgang C Primer from the Instructor Materials slides by

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

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