You are not logged in. Please login at www.codechef.com to post your questions!

×

C or C++ ?

I have come across many times that many good coders use C instead of C++. Why is so? I myself find C++ better for coding. Should I start coding in C?

asked 02 Apr '15, 17:58

sharru05's gravatar image

3★sharru05
5591723
accept rate: 14%


Well , one of the reasons for using C over C++ in competitive programming is because of the speed of scanf() over cin. scanf() takes less execution time than cin, and most new users who find out about this advantage use them, and hence, their code's might seem to be more like C , when they are actually C++ programmers ( the advantage of many C functions working on C++ is also to be noted ).

Please note that the more established users would use getchar_unlocked() over scanf(). This is one of the main reason for it. I'm saying this because that's what I used to do ( I'm sorry for bringing up my personal experience, but it is one of the main reasons ) . I was originally a C++ programmer, and I programmed in C++. But when I found about the speed advantage of using some C functions over C++, I started using them, and soon, the code would look entirely C.

So, since most part of C can be used on C++, it won't harm to learn C as well. But, it's better to have C++ as your main language and use C for certain parts ( like to improve speed, etc ). It's also good to learn C++ because of the large amount of Libraries available in C++.

But, the most important thing is to practice. With lots of practice, you can get better in any language ( but remember that no one is perfect and we all make mistakes , so it's nothing to be ashamed of to ask for help ) . So, when you choose to learn a language, make sure to work hard and always try to learn new things. In the world of programming, experience is what will help you get better, and there is no other shortcut than practice.

Happy Coding........

link

answered 02 Apr '15, 19:57

arun_as's gravatar image

1★arun_as
7413618
accept rate: 10%

Code in the language you are most comfortable with. C++ is an excellent choice due to its ready implementation of useful libraries, data structures and ready-to-use methods which you will have to write from scratch in C.

link

answered 02 Apr '15, 18:20

vastolorde95's gravatar image

5★vastolorde95 ♦
324
accept rate: 11%

As far as contests, use the latest version of C++ (currently C++14). As the above answer notes there are I/O performance issues to be aware of.

Outside of contests, there are many (often low-level) projects in C.

link

answered 02 Apr '15, 22:04

merolish's gravatar image

2★merolish
1
accept rate: 0%

C++ provides you stl and object oriented programming. Just see the below link i hope you would continue with c++ only.

link - http://tech.co/heres-a-ranking-of-the-highest-paying-programming-languages-2014-11

By the way i have seen many good coders in c++ also!!!

As per to your tags see -- http://stackoverflow.com/questions/497786/why-would-anybody-use-c-over-c

link

answered 03 Apr '15, 01:17

adi28galaxyak's gravatar image

5★adi28galaxyak
1164
accept rate: 14%

edited 03 Apr '15, 01:28

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,911
×1,477
×31

question asked: 02 Apr '15, 17:58

question was seen: 1,334 times

last updated: 03 Apr '15, 01:28