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, but 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 you reuse that throughout the code.
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 the 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 IDE (Integrated Development Environment), generally consisting of a GUI (graphic user interface), 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. It is distributed under the GNU General Public License (GPL). For detailed information check http://gcc.gnu.org.
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 Express C++ (freeware, Windows; step-into debugging,) Xcode (closed-source, Macintosh OS X, step-into debugging,) Eclipse, or Code::Blocks IDE with Mingw (open source, cross-platform; no step-into debugging.) Dev-C++ is often mentioned, but it doesn't seem to have seen active development in years, and can be very inconvenient to use. You can download a fully functional version of Dev-C++ free of charge from the developers website http://www.bloodshed.net/download.html. Another good IDE in Code::Blocks http://www.codeblocks.org, Dev-C++ is old and has been discontinued by its creator.
A fairly recent addition to this list is the Open Watcom C++ compiler and environment, which is available for several operating systems. 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 above listed operating systems, and compilers/IDEs are sufficient to learn to program C/C++.
This course covers everything, from the most basic principles of C++ up to 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, requiring developers to use external libraries or re-invent the wheel.
- 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 and Threads 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
- 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
- Quintus314 18:21, 15 April 2010 (UTC) using Wikiversity as well as many other sources to learn.
- Kamron, just looking around and trying it out while I'm at it. 14:09, January 11, 2010
- User:Chibisenpai 15 year old trying to learn C++ Chibisenpai 00:31, 2 December 2009 (UTC) :D
- Borgizzle 23:41, 2 July 2009 (UTC) using this to learn C++, I know some, but not a lot.. Thanks for this!
- Mason Swanson 13:58, 7 September 2009 (UTC) I Know A Little C++ But Hopefully We Can Help Each Other More! Knowledge Is Power!!!
- 184.108.40.206 15:53, 11 May 2009 (UTC)
- 220.127.116.11 23:01, 26 February 2009 (UTC) Cruzzz
- --Timmeh 1250 00:06, 22 January 2009 (UTC) Finally getting a grip on C++, thanks!
- Termine 23:57, 2 September 2008 (UTC) More programming stuff. Yeah!
- Dia0369 14:16, 13 April 2008 (UTC) Willing to learn pretty much everything there is to know about computer software, starting with C++. Thank you for the resources!
- Appolom 06:43, 1 April 2008 (UTC)I look forward to learning C++ thanks.
- Pjanssen 09:58, 11 February 2008 (UTC) After a stupid course in matlab in college it is time for the real stuff.
- J Blom 18:10, 9 January 2008 (UTC) I would love to re-explore the secrets of C++ -- Thanks guys.
- PGalasti 04:40, 7 January 2008 (UTC) I need to re-learn C++. Great site to re-learn.
- Thejamesman 18:28, 12 October 2007 (UTC) I look forward to learning. I have ALOT of computer modding and manipulation experience, but its time to get to the bare bones!
- Smartguy583 00:37, 30 September 2007 (UTC) This course seems so much more comprehensible that any of the books I've tried to learn C++ from.
- User:apcslkdanial21:00, 25 June 2008. I love wikiversity.
- Raspberry 21:58, 29 July 2007 (UTC) I love wikiversity. Learn, and pass on what you know! I'm learning computer science, and teaching physics, astronomy and music!
- Kafitz22 15:15, 24 July 2007 (UTC) Can't wait to start learning C++, although I know nothing except a bit of TI-BASIC :P
- Michael Z 07:42, 2 July 2007 (UTC) (Looking forward to learning the language of C++)
- Mortimir 01:15, 22 May 2007 (UTC)
- Giawa 17:51, 5 October 2006 (UTC) (Here to learn, have my code torn apart, try to help teach, everything)
- --SB_Johnny | talk -- Complete and total newbie. I'd like to become less ignorant about programming languages, and C++ was recommended as a good place to start for what I want to use languages for.
- Kwaggle 22:08, 20 December 2006 (UTC) C++ is my main proficiency, maybe I can pass some of it on.
- Josteinaj 22:55, 21 December 2006 (UTC) Here to learn. I know Java from before (as it is arguably easier, and very portable), but I'd like to learn C/C++ now. It would be great if the guide emphasized compatibility between platforms. Also, I eventually want to learn how to generate sounds, graphics and networking in C++.
- --18.104.22.168 22:00, 28 December 2006 (UTC)
- Miles32 06:45, 7 January 2007 (UTC) Here to learn C++. Im completely new to programming and I heard that c++ was the way to go.
- Blasterman 7 January 2007 -- C++ is my main programming language, so I'd like to sometimes help write the lessons. Never used C before, though.
- — Saivorgz 05:34, 12 January 2007 (UTC) -- January 11 2007 -- §wanting to learn c++ since i know java
- ex0du5 22:25, 12 January 2007 (UTC) -- Currently enrolled in Computer Engineering, and have taken 3 Java courses. I want to learn C++ as it is more efficient in programming visual and graphic intensive applications.
- Grimley 11:21, 21 March 2008 (UTC) -- just a learner plodding along.
- Modnar 09:31, 26 January 2007 (UTC) (Going to be doing this in university this year and would like to get a head start and always wanted to learn and now I have decided to do so and looking to use this also with creating Palm OS programs in the future hopefully as well :D)
- cybergig (02/01/07 5:02AM ) I'm a total newbie to this so I am here to quickly learn this language and hopefully several others to get a head-start on programming.
- Liam §wanting to learn c++
- Mattsan 19:27 10 Febuary 07 Totally new to programming but I'm really enthusiastic on learning C++!
- Chuboltite 10:00, 10 March 2007 (UTC) I've heard from multiple sources that C++ is a great language to learn. Plus, the programming experience will help me in my future studies, so why not?
- Chyld989 09:23, 11 March 2007 (UTC) I already know some C++, some of which I learned on my own and some of which I learned in school. Hoping to maybe learn a bit more, and maybe help others in the process.
- baci 09:26, 12 March 2007 (UTC) Like so many others, I'm here to learn and then teach. I wish I more experience so that I could assist with completion of this course.
- Devourer09 20:38, 22 March 2007 (UTC) Here to learn and if possible help others.
- 22.214.171.124 03:02, 21 April 2007 (UTC) Well, I could probably help, just need to find a topic that needs to be covered. maybe pointers?
- --Xentalion 00:57, 2 May 2007 (UTC) I'm here to help too, I've written a few programs in C++ and am hoping to help other people learn.
- Jocade 010 07:25, 21 May 2007 (UTC)
- --Topcount345 01:14, 22 May 2007 (UTC)|Talk I hope to learn more about c++, next year I am going to be in a class( by myself) in an attempt to learn c++. Starting to learn now in an effort to put a footstool in place to climb the wall this will probably be.
- Scooter 16:37, 23 May 2007 (UTC) I've been writing code for about 2 years, one of them with C++, I am most enthusiastic about wikiversity and I plan to contribute as much as I can.
- Cbradleyo 17:19, 18 June 2007 (UTC) Learned programming in high school, but that was over 10 years ago. Eager to learn C++.
- Aamirsayid1 20:51, 10 July 2007 (UTC)Aamir Sayid
- Cslashb 15:23, 12 July 2007 (UTC)
- ali2538 22:07, August 4 2007 (UTC) I wanted to learn this language since 7 years ago and every time that I started some thing happened. I hope I can be successful in it this time. I really want to learn c++. Good Luck to Everyone in learning C++. Including me.
- --Pajumed 02:12, 8 August 2007 (UTC) Just found out about wikiversity and I've wanted to learn C++ for a while, might as well if I want to do comp sci in college.
- Vitor 03:01, 14 August 2007 (UTC) To teach those who know less and to learn from everyone.
- jolt_34500 23:44, 28 August 2007 (UTC) Want to learn more about programming.
- Bensaved 06:57, 31 August 2007 (UTC) Senior Computer Science major, looking to learn more about other languages than Java.
- icecreamsoop 13:09, 11 October 200y (UTC) I'm looking to expand my programming knowledge beyond that of Java.
- 126.96.36.199 13:43, 5 September 2007 (UTC)User:ki4jgt
- User:Zlrussell 188.8.131.52 18:49, 17 September 2007 (UTC
- Drew 21:15, 2 November 2007 (UTC)
- Tommosimmo 09:03, 19 December 2007 (UTC)
- Speilberg0 23:47, 26 December 2007 (UTC)
- Captain panda 05:13, 5 January 2008 (UTC) I have only just learned a few weeks ago how little I really know about computers and I want to learn programming languages to help teach myself. C++ seems like a good place to start.
- Nofrak 05:04, 23 January 2008 (UTC) Expanse of knowledge
- Marmalade 20:26, 6 February 2008 (UTC)Hi, I'm hoping to learn some *stuff from this. I have very little experience in programming but I'm always willing to learn.
- Linuxlover101 21:12, 2 March 2008 (UTC) I've been really wanting to learn C++. I've had experience with web programming languages, but I need to move on.
- Coggz 18:37, 12 March 2008 (UTC) Learning C++ from a book and from here! GO wikiversity!! Oh, and GO Kubuntu!
- 184.108.40.206 08:11, 26 March 2008 (UTC)yash
- Adrian Parry220.127.116.11 11:30, 2 May 2008 (UTC)
- Billlava 19:23, 14 July 2008 (UTC)
- Zinigor 11:07, 7 August 2008 (UTC) I like what I see in Wikiversity so far. I hope this will help me learn C++. Thanks to all contributors!
- Dreamsjoint 08:07, 10 September 2008 (UTC) - Bonjour all, time for me to brush up a bit =]
- Maarten 08:58, 6 November 2008 (UTC) Hey, I'm an informatics student, and I'm willing to add some of my cources/exercises to the pages :)
- Swgeek54 04:01, 27 December 2008 (UTC)I am very enthusiastic about wikiversity, and hope to both learn and contribute here
- Cheekybrew 18:51, 15 January 2009 (UTC)programing language...what is wrong with me?
- AngMohClay 04:03, 21 February 2009 (UTC)
- Badgerbalti 12:06, 19 March 2009 (UTC)
- --StratoSphere99 13:00, 15 June 2009 (UTC)
- --Nirdh 09:50, 5 April 2009 (UTC)
- Briggszilla 23:27, 5 April 2009 (UTC)
- 64ByteKiller 13:11, 9 April 2009 (UTC) C++ is my main proficiency and I would like an opportunity to help others, especially as I was self-taught.
- Slackbheep 14:19, 2 May 2009 (UTC)
- Gert van den Brink 06:45, 25 June 2009 (UTC) - I'm trying to get some extra programming skills, and I thought that C++ would we a good start.
- Rr 06:02, 30 June 2009 (UTC]
- BCG999 signing out to learn C first... 17:53, 22 February 2010 (UTC)
- --Atishay811 17:57, 13 July 2009 (UTC)
- Davinci Incarnate 12:13, 3 August 2009 (UTC)I am completly new to code and programming, and from what I have found online C++ is the best place to start for my interests. Thank You Wikiversity
- Nulldev13 07:39, 13 September 2009 (UTC) i am pretty much interested in programming C++. nice to be here
- Ukuli 09:48, 3 October 2009 (UTC)
- Murukeshm 14:46, 15 October 2009 (UTC) I will try to learn from this article, and try to improve it where I can. Great work!
- 18.104.22.168 12:26, 19 October 2009 (UTC) Hamish Todd, student. Never programmed before except with Game maker, hoping this project will accomodate me.
- --horneddevil 11:35, 4 november 2009 (IGC) thijs de meester, student. Need to learn programming with C++ for a robot hoping thiscourse will help me with that.
- --Jomsamson 02:02, 5 March 2010 (UTC)Jomsamson
- Jhvid 11:58, 17 April 2010 (UTC) Trying to find out if C++ is the language for me
- PaulR8507 Trying to learn programming for Games
- Cybiko123 23:00, 7 May 2010 (UTC)
- Jukebox Emperor 15:37, 15 June 2010 (UTC) My school doesn't have any C++ courses. Looks like it's up to me to learn it.
- crappyprogrammer Trying to learn how to programme a few years before college.
- LazDude2012need to program Linux. ;)
- Salsarocket 17:23, 2 August 2010 (UTC)
- Minalear 19:46, 10 August 2010 (UTC) Wanted to get familiar with c++ during my high school years before I head off to college.
- La comadreja formerly AFriedman RESEARCH (talk) 02:33, 26 August 2010 (UTC) Writing a multi-class C++ program as part of graduate research.
- 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)
- Deitel (2008), C++ How To program, Pearson Prentice Hall, ISBN 9780136152507, http://books.google.com/books?id=HhGB8fOiUy8C
- [|Stroustrup, Bjarne] (2009), Programming: Principles and Practice Using C++, 10, Addison-Wesley, ISBN 978-0321543721, http://books.google.com/books?id=Ud7LLQAACAAJ
- Tutorial on cplusplus.com
- Thinkng in C++ by Bruce Eckel, A good free ebook on C++