Learning C++ programming

Hello,
What is the best way to learn C++ programming language that Arduino uses?

Is there any app for this for a beginer, or what do you think it’s the best way to learn it?

What previous programming experience do you have ?

No previous experience in programming

I would recommend to start with understanding the fundamentals of programming and the C programming language, there are online courses (eg https://www.coursera.org/learn/programming-fundamentals)

then read about the basics of object oriented programming

then go to C++

take your time, build solid foundations, don't take shortcuts.

the C Programming Language from the inventors of the language and the "hello world" program

Poor advice in the Arduino context - guaranteed disappointment when the Hello World program simply won't compile.

Let me emphasise something @J-M-L mentioned, because it is important:

You have two things to learn: programming, and the C language. (C++ can and should wait until you are competent in C).

The fundamental concepts of programming apply to any language and really must not be skipped. The C language implements those concepts in a particular (some would say old-fashioned, or idiosyncratic) way.

If you concentrate your learning the C language, hoping to pick up enough of an understanding of programming concepts along the way, then you will be handicapping yourself in the future.

So, you need a programming course that uses the 'C' language. Check @J-M-L's link, and use Google.

I profoundly disagree! The OP has no background in programming. K&R's reference work is absolutely NOT a programming tutorial! It's the worst possible place to start.

There are lot of apps available. Take time and study the offered apps to find the best point of start for your.

i've heard these criticisms before.

but when going thru web based tutorials, there may be questions that a more comprehensive book can provide answers to.

Thank you for all the replys. Do you guys think starting directly with an Adruino programming book is not a good ideea and learning C first would be better?

as I said, learn about algorithmic first. Understand what it means to program and the fundamental concepts behind it. when I work with youngsters keen to learn over the long haul, I even start with Boolean logic and truth tables as this is important.

there are lots to read, here are (random) examples

I would disagree, if your goal is to learn C++, follow an introductory course on C++, it covers all the basics you need, the first chapters of a C++ tutorial will teach the same basics concepts like functions, variables, control structures, etc. Unless you want to learn C specifically, starting with a C tutorial is an unnecessary detour. On top of that, there are multiple practices in C that are bad practices (our outright wrong) in C++, having to “unlearn” these bad practices when switching to C++, and having to remember where the differences between C and C++ lie is unnecessary overhead for a beginning programmer who just wants to learn C++.

If your goal is to learn Italian, it's best to follow a course on Italian, not first a Latin course and then an Italian course. Sure, knowing Latin will help you pick up Italian more quickly, but it's by no means a prerequisite.

I think the advice of learning C first stems from the fact that many older programmers first learned C and then later C++, which was a logical progression for them, but I don't think this is great advice for beginning C++ programmers. C++ is no longer a strict superset of C, and C++ doesn't depend on C knowledge.

In conclusion: you don't need to know any C to start learning C++.
If you want to learn C, use a C book/tutorial; if you want to learn C++, use a C++ book/tutorial.

Oh come on ... Sure, it was a great reference back in the day, but there are much better introductory books to teach programming concepts to beginners. And I would argue that ANSI C (C89) is not something you should be teaching to beginners in 2021.


I agree that having a structured book is an advantage.

A popular online book is https://www.learncpp.com/.
Like most programming books and courses, it is aimed at desktop development, so the setup of the development environment won't be applicable to Arduino.
However, if you really want to learn programming, having a good IDE and a platform that you can easily debug on is really useful. For programming exercises and debugging them, having to upload to an Arduino every time and having no access to a debugger is a bit cumbersome anyway.
Once you have some “desktop” C++ experience, you can easily apply this to Arduino later.

In my experience, many Arduino books focus for a large part on the hardware and the Arduino-specific functions/classes, and they often take a trial-and-error approach to programming.
If you want a solid programming foundation, it's much more efficient to follow a good book that specifically teaches you programming. Programming is built on exact rules, learning these rules correctly is much more productive than trial-and-error.

It rather depends what you're hoping to achieve. If you have some Arduino project in mind, you may be able to cobble it together from the IDE examples and whatever code you find on-line with a bit of help from forum members when you get stuck.

A lot of people seem to take this approach and if your project is one and done, it may even be the most efficient.

If on the other hand you want to learn to program, and then build Arduino projects, I suggest that you find a C++ tutorial that isn't Arduino focussed and work through the basics. You won't need to know how to build your own classes to start with, so when you reach that section of the course, stop and look at Arduino examples. They'll be much easier to understand with that learning behind you.

kernighan and plauger wrote Elements of Programming Style where they took example programs from college textbooks and journal articles teaching programming and revealed the flaws in the programs and how to fix and improve the programs (cargill wrote a similar book for c++).

so a tutorial site may be teaching flawed programming

a common problem with novice programmers is over complication. i believe a sound understanding of programming is necessary for programming in any language. i believe the book i suggested is concise and demonstrate good techniques.

but i agree a good tutorial site may be better for someone w/o any programming experience.

stroustrup said he believe it take 10 years to become proficient in c++

Or longer. I use C++ only because ppl write libraries using it, and I use the libraries. Sometimes. That's not really using it. I certainly don't know much about it.

I would recommend learning C outside the context of programming the Arduino. There are web based interpreters for C where you can comfortably learn, do your homework and experiment.

Meanwhile look at example code in the IDE to start getting a feel for the additional knowledge one must bring to successful small scale hardware orientated programming.

a7

1 Like

I think the K&R book is hopeless as a way of learning C or programming in general; however, it does work as a language reference book. But it's just too dense for most people, even professional programmers.

learning C or learning to program?

kernighan had said that many of the c++ books were mostly just c with "//" comments. they were also > 1" thick. what is wrong with being concise.

why is it hopeless (you don't explain)?

I see where you are coming from. You don't need C++ to program the Arduino at all, APART from two basic concepts:

1/ There are objects that can be created, and have methods inside them for doing stuff

2/ They use the dot notation for accessing those methods

Serial.println("Hello world");

There's an object called Serial that represents the serial link to your PC. It has a method in it called println() that lets you print a line of text up the serial link. You access the method using the . notation.

That's really all you need to get started. Making your own classes and objects can wait for later on. Inheritance, polymorphism.... all for much later.

Personally, though, I wouldn't use the Arduino for learning to program for the reasons already given - use an online tutorial.

Learning to program.

The K&R book is NOT a tutorial for people who've never programmed before. I can't believe we are still discussing this - you surely agree with that point.