1 / 10

C vs C++

CS-240 Data Structures Binghamton University Dick Steflik. C vs C++. C++ was originally developed to be the next version of C, not a new language. Similarities. same built-in data types same compiler preprocessor handles #include & #define

merton
Download Presentation

C vs C++

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 <stdio.h> 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 <iostream.h> int main(void) { cout << “Hello World\n”; return 0; }

More Related