C or Cpp which is better?

i have this doubt from when i started solving codechef problems.Now i am programming in C language only. Is learning complete C language is more adequate to become a good_programmer/master in codechef contests.I have learnt C and java(moderate) languages.I have been coding for 4 months in codechef.but i have observed that many programmers in this site solving problems in C++ language only…
So i have these questions…

is there any much more advantage of C++ over C in solving problems?

Do i need to learn C++ or is learning C language is sufficient to compete in programming contests?

Can we solve every problem in C language?

How to prepare for google code_jam,ACM-ICPC contests?

suggest me some good books for C++,DS,Algorithms…

Yes, for solving problems, C++ is definitely better.

C is sufficient for solving problems. But you will have to re-write things which are already present in C++ STL. For example a sort function.

Yes, you can solve every problem in C. You can solve every problem in assembly too. But will you solve these problems using assembly language?
Also, C++ is backwards compatible. (Almost) all C programs are C++ programs. So you lose nothing.

My advice is, learn C++. You will be able to save a lot of time in contests because so many useful functions and classes exist in STL.

9 Likes

There is not a lot of difference between c and c++ so transitioning is not too difficult. The main advantage of using cpp is the STL library. See this article (link) to see some of the features of stl which makes your life a lot easier and saves time particularly in short time based contests.

For learning DS/Algorithms, follow the CLRS textbook (link) and try to practice as many questions as you can on sites like codechef,topcoder,spoj,codeforces etc…

Also read the following tutorials on topcoder (link) and practice problems specifically on the topics you have read to understand how to apply them.

Good luck!

3 Likes

as said by @bhambya c++ is better for programming competitions for their STL functions and many more features which are not present in C .u can do better by c++ specially in programming competitions where time is so limited . for learning algorithm a data structures read the topcoder tutorials
,introduction to algorithm by coreman&… and check out this thread

2 Likes

from The Cathedral and the Bazaar:

…and we’re weighed down by a crappy
implementation language (C++).

being myself a newbie to prog circles, i am not in position of giving advice; however, i can post GREAT programmer Joel Spolsky’s GOLDEN ADVICE: http://www.joelonsoftware.com/articles/CollegeAdvice.html


Learn C before graduating Part two: C.
Notice I didn’t say C++. Although C is
becoming increasingly rare, it is
still the lingua franca of working
programmers. It is the language they
use to communicate with one another,
and, more importantly, it is much
closer to the machine than “modern”
languages that you’ll be taught in
college like ML, Java, Python,
whatever trendy junk they teach these
days. You need to spend at least a
semester getting close to the machine
or you’ll never be able to create
efficient code in higher level
languages. You’ll never be able to
work on compilers and operating
systems, which are some of the best
programming jobs around. You’ll never
be trusted to create architectures for
large scale projects. I don’t care how
much you know about continuations and
closures and exception handling: if
you can’t explain why while (*s++ =
*t++); copies a string, or if that isn’t the most natural thing in the
world to you, well, you’re programming
based on superstition, as far as I’m
concerned: a medical doctor who
doesn’t know basic anatomy, passing
out prescriptions based on what the
pharma sales babe said would work.


also have a peek here: http://www.joelonsoftware.com/articles/fog0000000319.html and http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

i feel obliged to mention their names also: Richard Stallman: http://stallman.org/stallman-computing.html, http://stackoverflow.com/questions/3210759/linux-developers-knowing-c and http://harmful.cat-v.org/software/c++/rms

Paul Graham: http://paulgraham.com/fix.html, http://www.paulgraham.com/icad.html and http://paulgraham.com/vanlfsp.html

Eric S. Raymond: http://esr.ibiblio.org/?p=532, http://en.wikiquote.org/wiki/Eric_S._Raymond and http://www.blogistan.co.uk/blog/mt.php/2008/10/10/the_enduring_appeal_of_c

however, being amateur prog i use combination of cpp and c :frowning:

1 Like

C is the mother language… C is the basic Language … C++ is made in C Programming Language, because of that there’s a lot of new functions and libraries made by C Codes. . C have a spectacular algorithms and data structures that the functions and libraries are made… C can enhanced your critical thinking and precise mind…so don’t depends on the functions/libraries… although the the codes is too long but your mind is purely functional… you are very powerful programmer if you master the C language… :slight_smile:

2 Likes

Agreed with you. You already covered every point I wanted to say.

the sort() function is a bad example. >> man qsort

1 Like

@vjnan369 thanx bro

definitely agree

  1. There is no such thing as mother language.
    C is awesome no doubt, but a language doesn’t depend on grammar defined by another one. Compliers can be two stage, but lets not go into those details.
  1. C++ is MADE in C programming language? really…its based on top of C as in an improvement. What about object oriented principles? where did they come from? certainly not from C.

  2. Lots of new functions and libraries made by C codes? - Libraries can be written for any language and i bet there are more libraries in other languages than in C,eg python

  1. C have a spectacular algorithms and data structures?- Your brain has algorithms, not C. Data structures are generic, a way to structure data. Data doesnt know that it exists in C or C++ or python. Data is data and ways to structure data exist in each and every language.

  2. C can ehnaced your critical thinking and precise mind- Problems do that, not languages. Language is just a tool to express yourself(to machine in our case)

  1. Although the codes is too long but your mind is purely functional- True and not true. Lets take an example- Lets say you are expert at sorting, you know many algorithms and have created library functions in C/C++/Python/Java/Scala/Closure/Erlang/…/English. HOW DOES LANGUAGE CHANGE SORTING TECHNIQUES?. Plus writing the same code over and over and over is bad. Why do you want to reinvent the wheel. There is a library which is optimized for different values of N. Why not use that? Why go over and try to create your own libraries which is anyways gonna fail corner cases given on codechef?.
  1. You are a very powerful programmer if you master C language- TRUE :slight_smile:

then what about priority_queues, binary search ??