• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

Is c or c++ better ?


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
shaan432
Asked:
shaan432
  • 6
  • 5
  • 5
  • +6
2 Solutions
 
Sys_ProgCommented:
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
 
Sys_ProgCommented:
As per my knowledge goes, everything possible in C should also be possible in C++

Amit
0
 
ssnkumarCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ssnkumarCommented:
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
 
Sys_ProgCommented:
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
 
ssnkumarCommented:
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
 
Sys_ProgCommented:
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
 
maheshptlCommented:
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
 
Sys_ProgCommented:
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
 
AxterCommented:
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
 
ssnkumarCommented:
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
 
Sys_ProgCommented:
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
 
akshayxxCommented:
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
 
info_expertCommented:
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
 
info_expertCommented:
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
 
sunnycoderCommented:
http://www.tgr.com/weblog/archives/000024.html

credit for this link goes to brettmjohnson
0
 
Avik DasguptaCommented:
>>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
 
Avik DasguptaCommented:
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
 
shaan432Author Commented:
Thank you all for ur help and advice. All of u were equally informative for me in this discussion.
0
 
ssnkumarCommented:
Then please award points to experts and close this thread:-))

-ssnkumar
0
 
info_expertCommented:
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
 
info_expertCommented:
I have sent the comment in response to the shaan432, he wrote:

>>All of u were equally informative for me in this discussion.
0
 
Avik DasguptaCommented:
He did the FCFS algorithm in awarding the points. ;-p
Well no regrets.
0
 
info_expertCommented:
What about FIFO ;-)
0
 
akshayxxCommented:
wish he knew how to sort.. dictionary order  ;-P
akshayxx, Avik, Axter.. and so on
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
  • 5
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now