Link to home
Start Free TrialLog in
Avatar of shaan432
shaan432

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Sys_Prog
Sys_Prog
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As per my knowledge goes, everything possible in C should also be possible in C++

Amit
SOLUTION
Avatar of Narendra Kumar S S
Narendra Kumar S S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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
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

Avatar of maheshptl
maheshptl

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
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


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
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
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
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
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
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?
http://www.tgr.com/weblog/archives/000024.html

credit for this link goes to brettmjohnson
>>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.
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.
Avatar of shaan432

ASKER

Thank you all for ur help and advice. All of u were equally informative for me in this discussion.
Then please award points to experts and close this thread:-))

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

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