8 Replies - 2198 Views - Last Post: 27 August 2008 - 08:51 PM Rate Topic: -----

#1 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Difference Between C and C++

Posted 26 August 2008 - 05:43 PM

What are the differences between C and C++? Is it like VB and VB.NET, or is there more to it?
Is This A Good Question/Topic? 0
  • +

Replies To: Difference Between C and C++

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3106
  • View blog
  • Posts: 19,145
  • Joined: 14-September 07

Re: Difference Between C and C++

Posted 26 August 2008 - 06:07 PM

C++ is an incremental improvement (well, the idea rather, i think it has made much more progress) over C (note the '++') C++ uses C as a subset and expands on OOP features such as classes, inheritance, polymorphism, etc...


Some call it C with classes, but i think that's oversimplifying. There are new ways of doing things such as dynamic memory allocation (i.e instead of using malloc, free, etc... you now use new and delete).

In C, there were structures, in C++ there are classes, which are essentially structs with methods (again, an oversimplification).


edited for typos

This post has been edited by KYA: 26 August 2008 - 06:08 PM

Was This Post Helpful? 0
  • +
  • -

#3 nirvanarupali  Icon User is offline

  • D.I.C Stomach
  • member icon

Reputation: 13
  • View blog
  • Posts: 1,119
  • Joined: 01-August 07

Re: Difference Between C and C++

Posted 26 August 2008 - 09:27 PM

In C we code our own bugs, in C++ we inherit them.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5880
  • View blog
  • Posts: 12,757
  • Joined: 16-October 07

Re: Difference Between C and C++

Posted 27 August 2008 - 04:37 AM

KYA explained it well. Additionally, there are some syntax gotchas. Basically, you can run C code in C++, but often not the other way around. Even if you're using only C functions.

Here's a code block for C++:
for(int i=0; i<size; i++ );



Declaring variables in the smallest scope possible is considered a good practice, but normal C will take offense at that one. It would need to be:
int i;
for(i=0; i<size; i++ );


Was This Post Helpful? 0
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Difference Between C and C++

Posted 27 August 2008 - 04:46 AM

Wouldn't this be better off in the C/C++ forum?

Along with "Is C++ a .NET language"

Both moved. :)
Was This Post Helpful? 0
  • +
  • -

#6 gatehallison  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-August 08

Re: Difference Between C and C++

Posted 27 August 2008 - 05:16 AM

c and c++ are different because in c++ there are some features that you can find in C++ that you can't find in C, coz C++ is an object oriented programming language means that it can use classes.
Was This Post Helpful? 0
  • +
  • -

#7 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Difference Between C and C++

Posted 27 August 2008 - 06:15 AM

C++ is a superset of C. Basically, everything that works in C will work in C++ but in C++ you get even more stuff to deal with, such as classes and namespaces. This new stuff in C++ is not backwards compatible, and therefore won't work in C.
Was This Post Helpful? 0
  • +
  • -

#8 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: Difference Between C and C++

Posted 27 August 2008 - 05:20 PM

Thanks Everyone!
Was This Post Helpful? 0
  • +
  • -

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Difference Between C and C++

Posted 27 August 2008 - 08:51 PM

@gabehabe -- C is not a proper subset of C++ -- by that I mean there are some C programs that will break when compiled on a C++ compiler. The languages are not 100% compatible.

Part of this is just updates in standards (C++ mostly implement ANSI-C99 but if you read K&R too literally you will find some of your code does not work the way you think it should). Part of this is subtle differences in the grammar.

To tell you the truth it is hard to find examples of C99 code that does work properly in a standards compliant C++ compiler. I believe if you scour the C++ FAQ from the news group discussion groups they have to occasional example where someone ran across a technical difference. (Though more often than not they are compiler specific examples).

Point being, that C++ does not advertise a 100% compatibility with C, just a "mostly compatible".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1