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

×

C or C++ which is better ?

Which is better to participate and solve more problems easily - C or C++, and why ?

asked 25 Jan '13, 23:30

praveen_kishor's gravatar image

1★praveen_kishor
40111313
accept rate: 0%


C++ is better because of STL and object oriented programming support and also you can use it like C(scanf and printf).

link

answered 30 Mar '16, 18:46

sahil_g's gravatar image

3★sahil_g
29814
accept rate: 16%

Advantages of C++ over C -
1) Supports OOP(Object Oriented Programming)
2) Standard Template Library
3) Many other in-built templates

link

answered 31 Mar '16, 10:24

hm_98's gravatar image

5★hm_98
2806
accept rate: 0%

edited 31 Mar '16, 10:24

C is widely used for Operating Systems, Kernels, other system softwares etc but for competitive programming, C++ is better as it gives OOP support, STL and you can use fast I/O even while writing cin/cost using "ios:sync _ with _ stdio(false)" or other related statements.

link

answered 31 Mar '16, 11:15

haresh_kh's gravatar image

3★haresh_kh
564
accept rate: 25%

C++ because of STL. STL involves many inbuilt functionality which is otherwise time consuming if implemented in C. For example algorithms like Dijkstra's Algorithm can be easily implemented with the help of STL in C++.

link

answered 25 Jan '13, 23:46

sourabh912's gravatar image

4★sourabh912
2545710
accept rate: 14%

Thanks sir.....but I have seen many codes written in both C and C++....and the same code written in c++ are longer then C ??

(25 Jan '13, 23:55) praveen_kishor1★

The code you write depends on your algorithm and the length doesnt matter. Moreover I think the codes in C++ that you have seen might have included many libraries and macros thus making the code look bigger.

(26 Jan '13, 00:09) sourabh9124★

Thanks sir.....what exactly is STL and macros are ??

(26 Jan '13, 00:13) praveen_kishor1★

STL stands for standard template library . It gives you in-built functions that you may use time and again.For example if you have a vector say vector<int> vec (that's the syntax for a vector) and you want to sort it . In normal codes, you'll perform merge sort etc. , which is time consuming. But, if you are using STl , then your vector gets sorted by the function called sort() . And, syntax would be , sort(vec.begin(),vec.end()) . So, that's all you would have to type and you get a sorted vector. Plus, using vector's and standard containers you get lesser segmentation faults. Similarly, there are many inbuilt templates for functions like sort,count, for data structures like stack etc.

Here are some links , that may prove helpful : 1.http://www.sgi.com/tech/stl/ 2.http://www.cplusplus.com/reference/stl/

I guess stl will help you code faster and it gives more focus on your problem , as you don't need to worry about algo's for functions like sort etc.

Regarding macro's , it's another way to reduce your code , say you are using you want to find the maximum of two numbers again and again , you need not call a function , instead you can invoke the pre-processor directive #define MAX(a,b) (a > b) ? a : b , which will return maximum of two numbers. But, use of macro's is your own choice.

So, I think c++ might be a better option considering the presence of stl.

link

answered 26 Jan '13, 09:14

ani94's gravatar image

2★ani94
5292410
accept rate: 5%

When dealing with macros, use proper parenthesis. Otherwise, you get unwanted results!!!

#define MAX(a,b) ((a) > (b) ? (a) : (b))
(26 Jan '13, 13:33) tijoforyou2★

I would say also c++ because of Standard Template Library.

link

answered 24 Feb '16, 11:20

alaganparikh's gravatar image

0★alaganparikh
1
accept rate: 0%

functionality vise C++ is better than . but to prepare for studies and to start programming i would recommend C.. Java can be used instead of C++, But C has no alternate. C is the obvious choice to many code starters and build programming skill and Mostly C is used.

link

answered 29 Feb '16, 22:00

gupta_2429's gravatar image

0★gupta_2429
11
accept rate: 33%

C++ is better than C because its support object oriented programming we create class and object of that class. there are many useful concept in C++ like friend function, Inheritance, polymorphism,Interface. also we can protect our data members

link

answered 22 Mar '16, 22:20

abhi7709's gravatar image

0★abhi7709
1
accept rate: 0%

There is no such thing like comparing C with C++. C stands for kernel, drivers and Operating Systems where C++ doesn't. Please stop comparing them....or saying that C++ is better than C.

link

answered 31 Mar '16, 03:10

tara24's gravatar image

0★tara24
261
accept rate: 16%

edited 31 Mar '16, 03:13

C++ was developed by Bjarne Stroustrup in 1983 at Bell Labs , as a "better C". C++ was an attempt to extend and to some extent change the C programming language to overcome some of the common problems with the language. i.e C++ is C incremented.

Features of C++

  • C++ is an intermediate-level language

  • C++ Supports principle of object oriented paradigm.

  • C++ gives access to lower-level functionality than other language

  • C++ have huge Function Library

  • C++ joins three separate programming categories:

      - the procedural language, represented by    C.
    
      - the object-oriented language, represented by the class  enhancements C++ adds to C.
    
      - generic programming, supported by C++ templates.
    
  • C++ is very easy to read and write.

link

answered 12 Nov '16, 20:35

rashedcs's gravatar image

2★rashedcs
49761755
accept rate: 4%

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,917
×1,664
×1,490
×148

question asked: 25 Jan '13, 23:30

question was seen: 3,993 times

last updated: 12 Nov '16, 20:35