You are on page 1of 5

4/24/2019 (1) IS C++ more difficult to learn than C?

- Quora

1
Home Answer Spaces Notifications Search Quora Add Question or Link

Learning C++ Learning C (programming language) +6 Related Questions

IS C++ more difficult to learn than C? What is the best approach to become more
proficient at C++?
Answer Follow · 2 Request
Is learning C++ still worthwhile to learn?
Ad by JetBrains
Is C++ fast?
Become a C++ guru with CLion.
Save time with code generation and ensure top code quality with CLion's code What is the fastest way to learn a programming
language like C or C++?
analysis and refactorings.
Is learning C still worthwhile?
Download at jetbrains.com
Is it possible to learn C# and C++ without learning
4 Answers C? Where can I learn?

Which is the best book to start C and C++ as a


Jerry Coffin, Guy who writes some code. beginner?
Answered Mon
What is the difference between C, C++ and C#?
It depends on what you mean by “learn”.
What are the best programming languages to
learn in 2014?
If you want to know all the dark corners of either language, it’s a lot of work—but
yes, there are more of them in C++, so learning all of them is more work. Which one should I learn first: C or C++?

For most people, that’s not a particularly useful thing to learn though. Most
 Ask New Question
people want to learn enough of the language to write code reasonably well. If More Related Questions

this is what you want, then C++ is actually quite a lot easier to learn than C.
Questions In Other Languages
The reason is fairly simple: C++ has a dramatically better library that integrates
Em português: Porque é o C++ mais difícil de
much better with the rest of the language.
aprender que C?

Let me give an example. Umm…how about a program that takes a text file as
input, and sorts the lines in the text file.

For the moment, we won’t worry a lot about its being as efficient as possible
either. We’d rather it wasn’t gratuitously inefficient, but for the moment we care
more about the code being simple, understandable and readable than its being
as fast as humanly possible.

So, in C++, I could do something like this:

1 #include <set>
2 #include <iostream>
3 #include <string>
4
5 int main() {
6 std::multiset<std::string> lines;
7
8 std::string line;
9 while (std::getline(std::cin, lin))
10 lines.insert(line);
11
12 for (auto const &aline : lines)
13 std::cout << aline << ‘\n’;
14 }

So: under 15 lines of code, and all of it simple enough that can explain it to
somebody unfamiliar with C++ in about 15 minutes or so.

Now, let’s consider what it would take to write an equivalent in C. If I’m going to
try to write something I can reasonably explain to beginners, I’m going to start
by simplifying it a bit. For starters, I don’t want to deal with reading strings of
arbitrary length. Doing that in C is more work all by itself than the whole
program above.

https://www.quora.com/IS-C-more-difficult-to-learn-than-C 1/5
4/24/2019 (1) IS C++ more difficult to learn than C? - Quora

Second, I’m going to do pretty much the same thing with the number
1 of lines—
Home Answer Spaces Notifications Search Quora Add Question or Link
I’m not going to try to deal with files containing an arbitrary number of lines;
instead, I’m going to set a fixed maximum, because (much like with strings of
arbitrary length) dealing with an arbitrary number of lines is just too much
work.

That’s enough limitations that we only have to write about three times as much
code:

1 #include <stdlib.h>
2 #include <string.h>
3 #include <stdio.h>
4
5 #define MAX_LINES (1024 * 1024)
6
7 int sort_func(void const *a, void const *b) {
8 return strcmp(*(char const **)a, *(char const **)b);
9 }
10
11 int main() {
12 char buffer[1024];
13 char **lines;
14 unsigned current_line = 0;
15
16 lines = malloc(sizeof(char*) * MAX_LINES);
17 if (lines == NULL) {
18 fprintf(stderr, "Out of memory error\n");
19 return EXIT_FAILURE;
20 }
21
22 while (fgets(buffer, sizeof(buffer), stdin)) {
23 char *temp = malloc(strlen(buffer) + 1);
24 if (temp == NULL) {
25 fprintf(stderr, "Out of memory error\n");
26 return EXIT_FAILURE;
27 }
28 strcpy(temp, buffer);
29 lines[current_line++] = temp;
30 if (current_line == MAX_LINES)
31 break;
32 }
33
34 qsort(lines, current_line, sizeof(lines[0]), sort_func);
35
36 for (int i = 0; i < current_line; i++)
37 puts(lines[i]);
38
39 for (int i = 0; i < current_line; i++)
40 free(lines[i]);
41 free(lines);
42 return 0;
43 }

So, I have to explain almost three times as much code. Worse, I have to get into a
number of concepts that many (most?) beginners find fairly difficult. Even fairly
experienced programmers often have to check and re-check a few times to be
sure they’ve gotten all the memory allocation and freeing done correctly.
Instead of 15 minutes of explanation, plan on at least a couple of hours. Worse
still, plan on the fact that virtually none of the students has learned much that
they can generalize at all—if I asked them to sort a file full of numbers
instead,most of them need to start over almost from the beginning, and ask new
variants of essentially the same questions all over again.

And, as noted up-front, this is still a very limited imitation of the C++ version. If
I want to support an arbitrary number of arbitrary-length strings, I need to get
into realloc—and based on my experience, that’s a solid hour of explanation all

https://www.quora.com/IS-C-more-difficult-to-learn-than-C 2/5
4/24/2019 (1) IS C++ more difficult to learn than C? - Quora

by itself (and looking on the web, it appears that about 99% of C programmers
1
Home Answer Spaces Notifications Search Quora Add Question or Link
have never actually learned to use it correctly, so most code that uses it is
subject to memory errors).

Summary

C has enough simpler syntax that’s it’s easier to learn to write a few really trivial
bits of stuff. But the minute you get past learning the first half dozen or so key
words, C++ is so much easier to use that learning to actually do something
interesting with it is substantially easier.
864 views · View Upvoters

Upvote · 21 Share

Add a comment... Recommended All

Sponsored by Commonlounge
Want to learn C++ from scratch? Start now for free.
Comprehensive 22-part course includes lots of coding exercises. Beginner
friendly, no prerequisites!

Start now at commonlounge.com

Kurt Guntheroth, Software Engineer and Writer


Answered Fri

Yes. C is a simple imperative programming language. If you’ve ever programmed


before, you can pick up C in about six weeks. Before C++ came along, this was
the way with programming languages. Six weeks for Pascal, six weeks for C,
ahem, two weeks for BASIC.

C++ is what you may call a multiple paradigm programming language. It’s
imperative syntax is identical to that of C, so to start with you’d need the same
length of time it took you to learn C.

But then you’d have to learn classes, and object oriented programming. OO
programming is quite subtle. It would take several months before you would
trust yourself to do anything with it.

Oh yeah, then there’s templates and template metaprogramming. You can spend
years learning that.

Oh, there’s exception handling too. And you need at least a basic understanding
of templates (for RAII) to use exception handling effectively.

C++ has a pretty big streaming I/O subsystem to learn.

Then there’s the standard library containers, algorithms, and iterators. That’s a
pretty big gulp.

My experience training professional programmers who already knew C was that


it took about two full-time years before you acquired a journeyman’s
understanding of C++, and that was before templates and exception handling.

Anyone, I mean anyone, who claims they can learn, or did learn C++ in six weeks
is full of the brown smelly stuff. Maybe you could learn enough to read other
peoples’ C++ code and then gradually acquire an understanding. But not to
actually use it unsupervised.
12.4k views · View Upvoters · View Sharers

Upvote · 245 Share · 1

Bulat Ziganshin, 27 years of C++ and counting

https://www.quora.com/IS-C-more-difficult-to-learn-than-C 3/5
4/24/2019 (1) IS C++ more difficult to learn than C? - Quora
6 months for PL/1, 6 months for Cobol, 1 year for Ada and the rest of life
1 fro Algol-68....
Home Answer Spaces Notifications Search Quora Add Question or Link

T.J. Duchene, Programmer for about 30 years at Self-Employment


Answered Sun

Yes. C++ is an over-designed language with features piled on one after another.
C++ has dozens of features and overlap. I have yet to meet anyone who has ever
mastered every aspect of C++. In order to understand C++, you not only have to
learn some 60 keywords, but you also have to understand multiple
methodologies. You need to know several versions of the C++ standard. You
need to know the C Standard library, because C++ lags on certain features. You
also need to know C linking, because C++ does not link with other languages
without it. On top of all of that, you must also know C++’s Standard Template
Library, which is very complex. In some cases, you must also know the Boost
Library.

C, on the other hand, has a clear and direct design, focused primarily on
minimalism. There is very little excess functionality. There are only 32 keywords
in most versions of C. You learn the C Standard Library (which is the same across
versions, minus a few new functions), and you are pretty much well equipped to
do what you need to.

The main difference between C and C++ is that C++ tries to think of everything
you can possibly need and “the kitchen sink” and adds it in advance. C gives you
the minimum, and you build out the rest yourself. C++ is less focused on writing
good code, and more interested in rapid development. C requires understanding
of how things work, while C++ tries to do everything for you (and fails
miserably).

In my opinion, C++ has a number of serious practical design flaws. For this
reasoning, many projects and some companies (like Google) ban the use of
certain C++ features.
500 views · View Upvoters · Answer requested by Jerry Noel

Upvote · 7 Share

Add a comment... Recommended All

Sponsored by Codota - Free AI Java Code Completions


Java made easy with AI code completions - Free.
Stop Googling for code: Free plugin for IntelliJ, Android Studio or Eclipse and let
the code come to you.

Download at codota.com

Javene Mcgowan
Answered 17h ago

CPP is light years more complicated. I don't programme in C, but I understand it


is a what you see you get stuff.

CPP allows a lot of implicit behaviour! This from a language that implemented
named cast to avoid the “dangers of C style cast”. I don't even use named cast
unless I really need to ensure only a static cast is done.

So CPP has lots of implicit behaviour. And no one book explains all of CPP
behaviour. CPP primer the best, still never mention ADA. Which is a nasty nasty
implicit behaviour of Cpp. Polluting your namespace without you.doing it
yourself . Mind you, ADA is very useful, but is over used by the language. And I
still don't have any text defining when exactly is ada used.

https://www.quora.com/IS-C-more-difficult-to-learn-than-C 4/5
4/24/2019 (1) IS C++ more difficult to learn than C? - Quora

Implicit constructors, move, copy, and their assignment version.1Also creating


Home Answer Spaces Notifications Search Quora Add Question or Link
classes is harder than using pure functions on structures
42 views

Upvote Share

Add a comment... Recommended All

7 Answers Collapsed (Why?)

Top Stories from Your Feed

Answer written · Learning to Program · 14h Answer written · Software Engineering · Topic you Answer written · Learning to Program · Mon
might like · 15h
Is C++ an easy or difficult I read that the logic errors are
programming language to learn If the average programmer is hardest to fix in programming
if you already know Java and C? writing less than 50 lines of code (compared to syntax and
per day, what does the rest of runtime errors). Can you show
Mario Galindo Queralt, Ph.D -
Artificial Intelligence Researcher their work day consist of? me an example of how
and CEO at PAITI Roman Andronov, Senior challenging these kind of errors
Answered 14h ago Software Engineer at Dow Jones might be to find and fix?
and Company (1999-present)
Learning C ++ is easy. Yes, easy. It's huge Rodrigo Irigoyen, I'm self-trained
Answered 15h ago
but easy. The problem is that there are developer and have successfully
several people who lie saying that it is Please remove the immature, naive and mentor dozens of great devs.
thoroughly erroneous perception that a Updated Apr 10 · Upvoted by Ehood
difficult because it is extensive. Do not
Garmiza, Over two decades of Systems
job of a C/C++ UNIX programmer amounts
believe them. Those people wan... (more) Programming
to only pressing the keyboard keys in a
Upvote · 35 Share · 1 A former zero-technical
proper sequence. For it is not. Simply be...
Read In Feed Read In Feed ReadinIn Feed
boss was specialist
(more)
finding “bugs” that

https://www.quora.com/IS-C-more-difficult-to-learn-than-C 5/5

You might also like