Presentation is loading. Please wait.

Presentation is loading. Please wait.

C vs C++ CS-240 Data Structures Binghamton University Dick Steflik.

Similar presentations


Presentation on theme: "C vs C++ CS-240 Data Structures Binghamton University Dick Steflik."— Presentation transcript:

1 C vs C++ CS-240 Data Structures Binghamton University Dick Steflik

2 C++ was originally developed to be the next version of C, not a new language.

3 Similarities ● same built-in data types ● same compiler preprocessor – handles #include & #define – conditional preprocessing #if, #ifndef and #endef ● same built-in operators on primitive types (+- /*……)

4 Similarities (cont.) ● Same built-in control structures – if, for, while, switch …. ● must have a function names “main” to determine where the program starts ● functions are defined the same way ● programs can be split up into separate files

5 Differences ● in C all code exists in function and the paradigm is that you manipulate data with functions ● in C++ classes are used to model the behavior of data objects, behavior is represented by functions and those functions are used to modify the object’s data

6 Differences (cont.) ● in C a struct is used to make an aggregate type and cannot have associated functions ● in C++ struct there may be associated (part of the struct) functions to process the data ● in C I/O is accomplished via library functions, in C++ it is done by using object methods.

7 Differences ● C++ has function overloading (two functions may have the same name), in C function names must be unique. ● C++ has operator overloading (operators can be redefined to do other things) ● C++ uses “nbew” and “delete” for dynamic memory management, C uses “malloc” and “free”

8 Simple C Program # include int main(void) { printf(“Hello World\n”); return 0; }

9 Software development in CS-240 ● various version of the GNU C++ Compiler – cygwin – unix like environment is on all PODS windows machines – Debian Linux – on all Linux Lab Machines – KNOPPIX – a bootable CDROM version of Linux (bring a 700 Mb CD to my office and I will burn a copy for you) – coLinux – installs as an icon on your Wondows desktop, KDE version of Debian (this is an easy way to get wireless internet for Linux). I will help you do this if you want to try it. Doesn’t require dual boot or a full Linux install – available on your Sun accounts – Eclipse w/c++ plugin and w/minGW – GUI IDE on Windows – Eclipse w/C++ plugin - GUI IDE on Linux

10 Simple C++ Program #include int main(void) { cout << “Hello World\n”; return 0; }


Download ppt "C vs C++ CS-240 Data Structures Binghamton University Dick Steflik."

Similar presentations


Ads by Google