Difference between C++ and C

I'd like to know the difference between these two giants, also want to know what can one do that another can't

thank you
LVL 13
Who is Participating?
CmdrRickHunterConnect With a Mentor Commented:
there's nothing that you can do in C that you can't do in C++ (because C++ is a superset of C)
theres things syntatcially you can do in C++ but can't do in C, but there's always a way of getting around it.
C usually results in less code bloat, and _CAN_ run faster, but with compilers these days the speed diference is nominal (and can be reversed because you might write code in C thats less optimizable)
C++ leads to more typesafe code, yielding fewer bugs, but requires more lines of code to write (usually).

The only major difference between them is the paradigm shift.   In C, you work with code, raw code manipulating memory.  The data structures (struct) in C are designed in a way to promote treating it as just a bunch of data.  You don't create a struct, you malloc() space in memory for it and then declare that space to be used for something.  In C++, because of its object oriented aspects, you work with objects - code and memory clumped into one mass.  Unlike in C, you create objects (MyObject* x = new MyObject), instead of just allocating memory for the objects.

If you're asking this question, I'm assuming you haven't programmed in either.  My advice, if you're just trying to learn, is to start with C++.  The only reason for this is the system of outputing to the screen and getting input from the keyboard is simpler and more intuitive than it is in c.

  char x[80];
  printf ("Please input a word:");
  scanf("%s", x);
  printf ("You typed %s at the prompt\n", x);

   char x[80];
   cout << "Please input a word: ";
   cin >> x;
   cout << "You typed " << x << " at the prompt" << endl;

the advantage of not having to learn printf() notation until later is indispensable IMHO
**ducks the incomming flames**
jkrConnect With a Mentor Commented:
C++ is an object oriented superset of C that supports templates. That's basically the difference.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

davidlars99Author Commented:
daaa, I knew that too...
So, then why (or better: what) are you asking about that? OK, 'C++' is two letters more than 'C', but...
grg99Connect With a Mentor Commented:
With C, you're handing a sharp machete to a baby.

With C++, you're handing a infinitely-adjustable 400HP 9000RPM running chainsaw to a drunk teenager.

All else is "syntactic sugar".

davidlars99Author Commented:
what is ANSI, can you describe it please
>>there's nothing that you can do in C that you can't do in C++ (because C++ is a superset of C)

That's not entirely true.
There are things you can do with the current C standard, that you can not do with C++.
C++ derived from an earlier version of the C standard.
The current C standard has variable C-Syle arrays, and macros that are not part of the current C++ standard.

void Function(int x)
 int data[x];

The above function is compliant with the current C standard, but not with the current C++ standard.
The current C standard has variable arguments for macro.  This is not part of the C++ standard.

#define DEBUGLOGGER(arg...) print(arg)

The above code will not compile on a C++ only compiler.
Some compilers, like the GNU compiler will allow C99 code to compile in C++ file, but most don't.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.