Solved

Is  c or c++ better ?

Posted on 2004-03-24
25
605 Views
Last Modified: 2010-04-15

Can c++ do everything that C language can do? If it can , is there any use in learning C ? I know the basics of c and c++,but I am in a confusion on which should I concentrate more for higher studies.I cant understand why many people are still clinging  on to C when C++ is available.
0
Comment
Question by:shaan432
  • 6
  • 5
  • 5
  • +6
25 Comments
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 30 total points
ID: 10674528
As quoted by many

C++ is "a better C"

C++ has all the features of C, rather C++ has better features/type checking as compared to C

Also, C++ as a language supports Object Oriented Development
Although OOP can also be done in C, however C doesn't have "constructs" which support OOP
On the other hand, C++ has language "constructs" which directly support OOP

So, C++ would always be a better language to learn (as per my opinion)

Amit
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10674533
As per my knowledge goes, everything possible in C should also be possible in C++

Amit
0
 
LVL 8

Assisted Solution

by:ssnkumar
ssnkumar earned 20 total points
ID: 10674541
Yes, C++ can do whatever C can do (may be in a different way) and more than that!
But, if performance is your criteria, then it's better to go for C.
And, No need to learn C before learning C++.
The major difference between these two languages is that:
C is written for structured programming.
C++ is written for object oriented programming (though structure programming is possible)
And C++ looks at everything as objects.
Everything depends on what type of programming and application you are doing?

-ssnkumar
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 10674558
Sys_Prog,
there are some things which is possible in C is not possible in C++! You may have to do it in a round about (different way) to achieve this!
For example:
struct X
{
   int a;
   int b;
};

main()
{
   struct X x1 = {a : 10, b : 20};
   struct X x2 = {b : 10, a : 20};
}

The above program works fine with C. But it is not implemented in C++!

-ssnkumar
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10674560
Hi ssnkumar,

As per whatever little knowledge I have, C++ program (if written/designed carefully) won't lead to performance degradation as that of a similar program in C


Amit
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 10674575
In case of virtual functions, the way it is implemented is going to affect performance. It has to go to v-table and then from there to the correct function.
If the same program is done in C, since there is no objects-virutal functions, we are bound to do it in different way and I think (I am not sure) it will take lesser time....

-ssnkumar
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10674594
ssnkumar,

The example u gave above doesn't seem to have any functional significance
I presumed that the questioner needs to compare C and C++ from a functional perspective and NOT technical details

C++ has many many technical features which might not be even possible in C (by any means)

Having said that, I do not underestimate C - that is where I started and enjoyed programming
Amit

0
 

Expert Comment

by:maheshptl
ID: 10674599
Hi,
  As of my opinion is concerned C++ is better , but it depends C is widly used in system level programming like device drivers etc... than c++(i dont think C++ is used in system level programming) and C++ is OOP langauge ,more widly used in Application level.

-Mahesh
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10674609
Regarding virtual functions

C++ does not force any programmer to use virtual functions
Its upto the programmer to declare a function virtual OR not (Java doesn't provide this facility)

And the dynamism provided by virtual functions with so much less code would definitely be better than the approah to implement it in C

Amit


0
 
LVL 30

Expert Comment

by:Axter
ID: 10674618
There other things that you can do with the Current C Standard that you can NOT do with the current C++ standard.
Such as Variable Array and Variable Marco arguments
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 10674654
Sys_Prog,
That's the reason I wrote in my first post:
>Everything depends on what type of programming and application you are doing?
I think you are much more experienced and know more C++ and C than me! So, I go with what you say regarding this comparison:-)

maheshptl,
Sony Software Architecture Division have implemented proprietery OS (it is both Embedded and Real Time) in C++:-))
So, no need to assume that C++ is not used for systems side work.

In my opinion, since both are different languages, it is better to learn both. But, before learning C++, OOP has to be understood, without which you will be doing C programming with .cpp extension:-))

-ssnkumar
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 10674667
Yep, it all depends on the task at hand

And regarding the experience, I really did not mean to "underestimate C" or "oppose your opinio" as I posted in my previous post. (Apologies if I have done that)

Amit
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:akshayxx
ID: 10674676
not going to say anything different,
"beauty lies in the eyes of beholder"
So to answer a question which one of CPP and C is better, it all depends on what you look for.
1. if you want some lightweight language, to write device driver/embedder programs, then C definitely is better.
2. if in any sense u need OOA features, or are planning to develop large scale projects, then you are going for suicide if you take it with C.
Overall, since anything C can provide is there in CPP, CPP is better than C.

but to program efficiently in CPP or C or any other language, you need to have good understanding of much more stuff than just the CPP language. primarily, algorithms and data structures, and if it involves Objects/classes, then 75-80% of project is done when you have your OO design done.

hope it made some sense.
Akshay
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10674717
Hi,
It depends upon your goal as what kind of tasks you want to achieve. If you want to go for:

- Realtime Operating System.
- System Programming.
- Automation and robotics
- Hardware interactive softwares.
- Embedded Devices programming.
- Writing Drivers.

Then you choose C.

and If you want to go for :

- More rapid development.
- Business domain softwares.
- High level programming
- Designing Activx

Then you choose C++.


But keep one thing in mind that you should only choose C if you want very fast executions at low level. Otherwise it is a timetested practice to use C++ if the speed of execution is not a big critical issue.


Also Have a look at this link:

http://discuss.extremetech.com/n/main.asp?webtag=extremetech&nav=messages&msg=40985.9
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10674721
Also:
>>is there any use in learning C ?

You will have to learn enough C even if you only want to go for C++. Because C++ is based on C and not the C based on C++.

Got my point?
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10675208
http://www.tgr.com/weblog/archives/000024.html

credit for this link goes to brettmjohnson
0
 
LVL 2

Expert Comment

by:Avik77
ID: 10679827
>>You will have to learn enough C even if you only want to go for C++.
I don't agree to this at all. It is a general approach for many C programmers to use C like features in C++ programs where it could have been better implemented by C++ features. C++ is misused in many programs written by "C programmers trying to learn C++" just by punching C features thoughtlessly.

Anyway, OOP is a feature which u cannot do away with. It will make program development easier and finer. C++ also provides generic programming facility and is much more expressive than C in terms of types and structures. The Standard class library and template library provides many built in datastructures by which u can much more efficiently implement difficult concepts. I vote for C++ and don't think C as prerequisite for learning C++.

Avik.
0
 
LVL 2

Expert Comment

by:Avik77
ID: 10679892
U must definitely concentrate on C++ for ur higher studies as it supports many modern concepts of programming which C does not ( if it is a compare between C and  C++ as there are other languages like Java which also support OOP). Again C++ unlike Java does not enforce u to use classes. U can program in C++ just like in C hence Why C ????????

Avik.
0
 

Author Comment

by:shaan432
ID: 10684698
Thank you all for ur help and advice. All of u were equally informative for me in this discussion.
0
 
LVL 8

Expert Comment

by:ssnkumar
ID: 10684772
Then please award points to experts and close this thread:-))

-ssnkumar
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10695173
Ok,
By the way
Giving the points according to wish is the right of the person asking the question , But in my opinion, it is very unfair to split just 50 points and only among two users. Its just like celebrating the birthday by slicing the pea bean. ;-p

Regards.
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10695182
I have sent the comment in response to the shaan432, he wrote:

>>All of u were equally informative for me in this discussion.
0
 
LVL 2

Expert Comment

by:Avik77
ID: 10695261
He did the FCFS algorithm in awarding the points. ;-p
Well no regrets.
0
 
LVL 5

Expert Comment

by:info_expert
ID: 10695313
What about FIFO ;-)
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 10701435
wish he knew how to sort.. dictionary order  ;-P
akshayxx, Avik, Axter.. and so on
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now