Solved

Difference between C++ and C

Posted on 2004-10-11
8
250 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:davidlars99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 20 total points
ID: 12278573
C++ is an object oriented superset of C that supports templates. That's basically the difference.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12278589
0
 
LVL 13

Author Comment

by:davidlars99
ID: 12278660
daaa, I knew that too...
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!

 
LVL 86

Expert Comment

by:jkr
ID: 12278689
So, then why (or better: what) are you asking about that? OK, 'C++' is two letters more than 'C', but...
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 20 total points
ID: 12278703
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".

0
 
LVL 3

Accepted Solution

by:
CmdrRickHunter earned 460 total points
ID: 12278982
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.

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


C++:
   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**
0
 
LVL 13

Author Comment

by:davidlars99
ID: 12279459
what is ANSI, can you describe it please
0
 
LVL 30

Expert Comment

by:Axter
ID: 12279669
>>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.

Example:
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.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

632 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