Welcome to the C++ programming language. Whether you're not certain which language to pick or you've already decided on C++, you've come to the right place.
C++ is arguably the most versatile language in common use. C++ allows for both high-performance code as well as expressive abstractions and design constructs. The language is not perfect but it does represent an excellent compromise between these potentially conflicting language capabilities. C++ combines "low-level" programming tailored to specific machine architectures with "high-level" programming, which can allow code to be completely abstracted from any particulars of the machine executing the program. Both approaches have pros and cons that we'll cover in this tutorial. If interested, Wikibooks also has material on this subject.
Why should you learn C++?
The C++ language originally derives from the imperative language C. The defining feature which distinguishes C++ from C is support for Object-Oriented Programming (OOP). This makes C++ a multi-paradigm programming language. An example that can help to demonstrate what OOP means:
If you were writing a program to track the statistics of a racing cyclist, you might make different parts of the program for their age, years of racing, wins, falls, what teams they've raced with and so on. In real life, though, that's not how we think. Instead, we would think of the cyclist as a whole, and the different statistics as being part of him. We could also apply that general "model" of a cyclist, maybe with a few modifications, to any cyclist, and have a complete representation of them. This is the essence of object-oriented programming, and as you understand it more fully, it will allow you to create powerful, yet easily-understood programs. Instead of relying on data that is scattered throughout a program, you can create a block of code that defines everything you need, and then reuse that throughout the program.
As a further example, think of a motor car. You unlock it with the key and get in. Then, you turn the ignition, put the car in reverse, release the brake, and press the accelerator. As you drive, you use the steering wheel, the brake, and the accelerator (and maybe the clutch). You don't know or need to know all the specifics of the car to make it work. You just use what you need, and it's simple, too. Object-oriented programming is like that. You can make powerful code, but it's all hidden, and you can interact and reuse that code using simple controls.
Other languages, such as Java, Python, Smalltalk and C#, allow the programmer to write code in this object-orientated way. The key difference between C++ and these languages is that C++ is designed to be compiled into efficient low-level code which can run directly on the processor of a computer. This ability means that C++ differs in many ways from these other languages, and lacks many of the advanced facilities you might be familiar with if you already know one of them.
Your enthusiasm. This is meant for a first-time user. Every lesson will only depend on what has already been taught in previous lessons. All you need here is your willingness to learn, experiment, and have fun with computers.
Get an integrated development environment (IDE), generally consisting of a graphical user interface (GUI), a compiler (transforms C/C++ code into a machine-readable program) and a text editor. Most C++ IDEs use the GNU C++ compiler which is part of the GNU Compiler Collection (GCC). This is a program from the Free Software Foundation distributed under the GNU General Public License (GPL). For detailed information, check the official GCC webpage.
Some might say that it is important to learn to edit code using an editor and compile it manually. There is time for that later; the manual editing process changes depending on system and compiler, so put it off until you can write significant programs.
Recommendations for an IDE are Microsoft Visual Studio Community C++ (freeware, Windows; step-into debugging), Xcode (freeware, Macintosh OS X; step-into debugging), Eclipse (free and open-source, cross-platform; step-into debugging) or Code::Blocks with Mingw (free and open-source, cross-platform; no step-into debugging). Dev-C++ (free and open-source, Windows; step-into debugging) is often mentioned, though it hasn't seen active development in years. A fairly recent addition to this list is the Open Watcom C++ compiler and environment (open-source, cross-platform; no step-into debugging).
Most of the compilers/IDEs listed here are native to the Microsoft Windows operating system. C/C++ was born on UNIX, and there are several free UNIX operating systems such as FreeBSD. C/C++ comes with most GNU/Linux variants. Any of the operating systems and compilers/IDEs listed above are sufficient to learn to program C/C++.
This course covers most introductory & intermediate topics of C++, starting with basic priniciples and working up to more advanced concepts such as polymorphism and inheritance.
Pros and Cons of C++
- Is extremely popular, and therefore lots of support is available.
- Has a large base of freely available code for download, while also supporting direct integration with ASM and C.
- Is very powerful, and can be used to create just about any program, including low-level system programs.
- There is a compiler for C++ on every major operating system. C++ programs that are purposely written for portability will work on many major operating systems with little change in code.
- C++ is a language which is compiled (transformed from human readable code to low-level machine code), so it can often run faster than languages such as Java, Python, and C#, as it does not depend on an interpreter or a "run-time environment" which must be loaded beforehand.
- Has a long-established usage base that likely guarantees support for the language will continue for quite some time.
- Many languages are based off of C/C++, such as Java, so knowledge in C++ will make it easier to understand these languages.
- Has a relatively small associated C++ Standard Library as compared to languages such as Java's Standard Platform SDK or C#'s .NET Framework, permitting greater versatility and reducing the system footprint of resulting compilations.
- Has been standardized by the International Standards Association as ISO/IEC 14882 with significant versions of the standard released in 1998, 2003 and 2011.
- Has a significant number of open source libraries available, including the Boost which are freely and widely available.
- It is not very safe by itself, as it lacks automatic boundary checks, invalid pointer checks, etc., allows for invisible side-effects (causing non-deterministic behavior) and allows implicit type casting. Many security issues and memory leaks are a direct result of this, unless an extra effort is made to prevent them.
- By default, there is no built-in memory management, even if smart pointers introduced from C++11 allow automatic resource managment.
- Its OOP system is rather archaic, requiring explicit virtualization of methods among other things usually reserved for older languages.
- Lacks the ability to define completely custom operators. (Not to be confused with the ability to define custom implementations for a hard-wired set of operators, which C++ has.)
- Does not offer full algebraic data types.
- Functions are not first-class types. (Although pointers allow for workarounds.)
- Has a somewhat more difficult learning curve than some other languages. For instance, C++'s most powerful features, such as templates, have a very complex syntax.
- Is very picky how code is formatted (but not quite as picky as FORTRAN, RPG or Haskell)
- GUI, Networking aren't standardized, requiring the use of non-standard, third-party libraries (though many such libraries, both free and commercial, are available, as is the possibility to use C libraries), Boost being one of the preferred. The lack of a standard, however, may hamper learnability and interoperability or at least require some extended investigation.
- Lesson 1: Introduction to C++
- Lesson 2: Variables and User Input
- Lesson 3: Simple Math
- Lesson 4: Conditional Statements
- Lesson 5: Loops
- Lesson 6: Functions and Recursion
- Lesson 7: More Functions
To be merged
You can add your name here or on the enrolled sub-page. You should resign your enrollment each year about if you want to be considered an active enrollee. Enrolled
- W4RP1G 00:13, 28 April 2012 (PST) Learning to solve problems!
- Zalteroth 10:00, 8 November 2010 (GMT) Trying to write powerful yet small programs to change the way people use computers.
- Cap356 18:47, 19 October 2010 (UTC) learning to change the world!
- Tavoricko 16:58, 1 July 2010 (UTC)
- Zngga 22:34, 14 June 2010 (UTC)Moving from Java to C++!
- Moxo 13 May 2010. It's been a while since I programmed so I guess I'm starting again, afresh.Moxo 13:47, 13 May 2010 (UTC)
- Tarif Ezaz 06:56, 5 May 2010 (UTC) I believe "sharing" Knowledge is power, and with wikiversity for that reason :D
- Zendegi 05:06, 29 November 2010 (UTC)Looking to refresh after 15 years away, with a complete lack of OOP
- KReeves 00:22, 21 January 2011 (UTC) Also taking C++ in college. Looking for a new perspective to help me better understand.
- Alex_loves_you 10:52, 25 April 2011 (UTC) Really into web development. Looking to expand my programing horizon. Love this website by the way.
- hilq 12:48, 19 June 2011 (UTC) I can also help about your C++ development at hand.
- L1ght5h0w 16:23, 12 August 2014 (UTC)
- Varun Tokas (discuss • contribs) 13:52, 28 February 2016 (UTC)Learning C++ to get into our school computer club as youngest programmer
- Snitch (discuss • contribs) 09:26, 28 June 2013 (UTC)Moving from VBA to c++ (beginner). WikyU looks great!
- Muhammad j yakubu (discuss • contribs) 08:52, 27 December 2016 (UTC) Looking for the way to create a powerful program in c++ (Beginner)
Jangoon the dumab
- Deitel (2008), C++ How To program, Pearson Prentice Hall, ISBN 9780136152507CS1 maint: date and year (link)
- Stroustrup, Bjarne (2009), Programming: Principles and Practice Using C++, 10, Addison-Wesley, ISBN 978-0321543721CS1 maint: date and year (link)