CS225 : Data Structures and Software EngineeringIntroduction to C++Jason Zych
c 2001, 1999 Jason Zych2
Chapter 1Introduction to C++1.1Why C++?In this class, the data structures you learn will be taught from a general viewpoint, and thelessons you learn will be applicable regardless of the particular programming language you use.However, we do want to give you actual programming practice with these ideas as well, and inorder to do that, we need to choosesomelanguage to use. So, why C++ and not Java? Well,there are three reasons:1. First, independent of any particular language merits, knowing C++ will be helpful for youin the future just as knowing Java will be helpful for you in the future. At the completionof the first two software courses – CS125 and CS225 – you will know the two most widelyused “new” languages and will be prepared to use either language in future courses andresearch, and also in industry work (whether job or internship). From that point of view,knowing only Java after the first two software courses would not be as beneficial for you.In addition, C++ is more or less a subset of an older language, C. Certain things you cando in C still can be done in C++, but they tend to go unused in favor of new features.However, the basics are still the same, and since a great deal of today’s legacy code iswritten in C, if you have a project in the future that requires you to know C, you alreadyhave a significant head start. So, before we even get into the “learn C++ for what thelanguage itself can teach you” arguments, the case can be made that knowing C++ willlikely be quite helpful for you in the future simply due to its usage in much software inthe real world.2. Second, and more importantly, there are features and concepts that are in C++ and notin Java, or that are similar to those in Java but implemented differently, and it is helpfulto be familiar with those ideas. In particular, the concept of pointers – an idea not presentin Java – carries with it a large number of other concepts that need to be learned, not theleast of which is a solid idea of what isreallygoing on in the computer’s memory as yourprogram compiles and runs. This is an idea that can be glossed over in Java due to Java’shigh level of abstraction. C++ has a slightly lower level of abstraction in many cases –youcanprogram in a high-level of abstraction, but you can also explore more details in aneffort to optimize your software. Learning these ideas will give you a better understandingof the interface between programs, compilers, and memory, and therefore will serve as anice introduction to future courses, where you will be exploring machine architecture and3
compilers in greater detail.Further, with every language you learn, the next languagebecomes easier to learn, and so learning the differences between C++ and Java will notonly mean you know C++ for its sake, but it will help build the ability to learn newlanguages and ideas quickly, which is a skill that is useful in coursework, research, andindustry alike.