What are the main differences between C and C++?

cchen

Diamond Member
Oct 12, 1999
6,062
0
76
Next semester I'm gonna take a data structures class, and I can choose between C and Java. I'm really good at C++ and I hate java, so I would rather take the C class. I haven't even touched C before, so what are the main differences?
 

Bloodstein

Senior member
Nov 8, 2002
343
0
0
Hmn. C is (in my humble opinion) much "lower-level" compared to Java or C++. I would personally go with Java when learning data structures cuz it allows you to focus more on the algorithms, etc rather than minor issues such as memory management (which u'll have to manage on your own with C). Having said that, there are things that you can never do with Java that you can with C (eg. get the memory address of a variable)....but with data structures, I'm sure you'll do fine with Java.

Also your excellent background in C++ would mean you're already familiar with OO concepts...so Java shouldn't be a problem being almost entirely modelled on C++.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
C++ is object oriented, C is not. That's the difference.

Basically that means that in C you have a bunch of global variables, functions (with local variables) and maybe interfaces if you are nice.
Code in C is not very readable, but it is indeed relatively low-level. Oh, and you can only define variables before the code. But it stops you from making out of scope errors.

C++, however, relies on objects (a struct that also contains a function, sort of speaking) and is similar to Java, yes.

C is still the choice for device drivers and low-level OS functions. It is normally faster than C++.
If you are proficient in C++, I see little use in taking a C class, since most of it is just a subset of C++. If you ever programmed in Pascal or Fortran before, you know what the differences are anyway.

Edit: Fixed one C / C++ mistypo.
 

Ynog

Golden Member
Oct 9, 2002
1,782
1
0
Having learned C++ before C, going to C isn't all that difficult. Basically what every has described cover the differences.
There are a few more but most of them are minor. Now one thing I noticed when doing C for the first time.
You will catch yourself saying that basically C is a broken C++. Its not hard to go from C++ to C.
If you do, might want to invest in Kernighan and Ritchie's "The C Programming Language" the book
is worth having.

Just note there are minor coding differences between C++ and C, things C++ allows and C doesn't. And
alot of time the error messages aren't all that clear.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Instead of "new" and "delete", you use malloc() and free(). You use classes instead of structs. It won't be hard to learn C after learning C++. For that matter, java is also easy. Java is, for all practical purposes, a subset of C++. To turn C++ into java:
1. remove all *'s
2. turn your -> into .
3. put "class blah { }" around the whole program. Oh, and remove all delete's.
 

thornc

Golden Member
Nov 29, 2000
1,011
0
0
C++ as the "++" states is a superset of C and not the other way around.
And many of the good non OOP things in C++ like the place where you can define variables has been adopted in the new
C99 standard!

And a programming language is what a programmer makes it be!

 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Originally posted by: thornc
C++ as the "++" states is a superset of C and not the other way around.
And many of the good non OOP things in C++ like the place where you can define variables has been adopted in the new
C99 standard!

And a programming language is what a programmer makes it be!

Good point. A LOT of stuff from C++ is in C99.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
C
You shoot yourself in the foot.

C++
You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, ``that's me, over there.''

from here :D
 

thornc

Golden Member
Nov 29, 2000
1,011
0
0
Originally posted by: RSMemphis
Originally posted by: thornc
C++ as the "++" states is a superset of C and not the other way around.

Did anyone here claim the opposite? I think not.

You last post came close to state that... I was just stating it in a clear way....
But it did get the main difference beetween C and C++ in that post:
C++ is object oriented, C is not. That's the difference.

 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Saying C++ is OO and C is a rather poor means of identifying differences in the languages, imo.

I've worked on a lot of projects that had code written in C++ that the only discernable difference between it and C was it's declaration of variables mid-scope. I'll regurgitate the mantra:

"Good C is also C++"

C++ has inherent syntactic facilities to elucidate the representation of OO methodologies, whereas C would require a lot of "syntactic salt" to get the same results. Yes, OO is possible in C. The first C++ "compilers" (called "C with Objects" at the time I believe) actually emitted C code.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
I would describe C's relationship to C++ by saying that some of their syntax is similar. And that's about it.

I find it rather limiting to program in C after programming in C++ for so long.
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
Originally posted by: thornc
Originally posted by: RSMemphis
Did anyone here claim the opposite? I think not.
You last post came close to state that... I was just stating it in a clear way....
But it did get the main difference beetween C and C++ in that post:
C++ is object oriented, C is not. That's the difference.

I see little use in taking a C class, since most of it is just a subset of C++.

C being a subset of C++ means the same as C++ being a superset of C.

I know you just meant well, but it's funny nonetheless. :)
 

BobShimits

Junior Member
Nov 10, 2002
9
0
0
for beginner's c++ makes coding alot faster. that's the simaler reason I want to learn J++ compared to J
jJ
 

manly

Lifer
Jan 25, 2000
13,164
3,947
136
Originally posted by: BobShimits
for beginner's c++ makes coding alot faster. that's the simaler reason I want to learn J++ compared to J
jJ
I hope you're kidding because (at least the latter part of) your comment is hilarious and ridiculous.

I'm glad Descartes finally chimed in with some meaningful discussion. singh too, but I'm not quite convinced I agree with his general thesis.

While C++ is very popular for Windows native application development, I sense that the book on C++ is that it's not a great programming language. Mainly the complexity level goes off the charts, and the standardization effort is still ongoing. In a way, it's an indictment of the standardization by committee route.

C, on the other hand, while relatively too low level to be a general purpose language, still has a high reputation amongst users and purists. It's a fairly small language, ubiquitous, by most accounts well-designed, and still the first choice for systems programming. The main reason C fell out of favor is because OOP was viewed as a better way of constructing massive, large applications where the LOC goes into the millions. Without namespaces, C becomes a chore to scale to huge programming projects, but it can be done if guidelines on identifiers are designed in from the beginning and adopted by everyone involved.

If I were to bet, it would be that C will outlast C++ in mainstream usage.
 

ynotravid

Senior member
Jun 20, 2002
754
0
0
Originally posted by: thornc
Originally posted by: RSMemphis
Originally posted by: thornc
C++ as the "++" states is a superset of C and not the other way around.

Did anyone here claim the opposite? I think not.

You last post came close to state that... I was just stating it in a clear way....
But it did get the main difference beetween C and C++ in that post:
C++ is object oriented, C is not. That's the difference.
C++ has like another 32 libraries to get familiar with. To me that is the biggest difference.

There's a lot of people who actually know virtually all of C, but it's next to impossible to learn all of C++.