Depends on what your friend means.. does he mean use C++ language features to solve the problem that is solved using C..
Or does he mean just make this code compile using a C++ compiler.. ?
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
from what i understand C++ is a subset of C so all C code should compile in a C++ compiler.
Next you'll say Earth is the center of Universe.. :D
C++ is superset of C.what he mean is using C++ language n code.. what is the dif.. how can i change it
There is a subtle difference between using C++ language to code and using C++ language's features (that are NOT available in C) to code.
In simplest terms C is procedural and C++ is Object Oriented. So to really use the features of C++ you should have some classes and objects and so on..
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
so all C code should compile in a C++ compiler.
No it won't. C++ made several syntax changes such as c++ requires type casts where C does not. Here is a more complete list of differences .
One way to make your code more c++'ish is to replace all printf() function calls with cout that is declared in header file and remove c++ standard header files to not have the .h extension.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
No it won't. C++ made several syntax changes such as c++ requires type casts where C does not. Here is a more complete list of differences .
One way to make your code more c++'ish is to replace all printf() function calls with cout that is declared in header file and remove c++ standard header files to not have the .h extension.
In THIS particualar case, the code may indeed compile under C++.
It's definately C. I am embarassed to say that I don't even understand what the arguments in a printf() do! I'm comming in late in the game, so I'm more or less C++ only. I've been steering clear of C for now for fear of confusing the two. In reality I will need to know both.
JRM
Practically a Master Poster
621 posts since Nov 2006
Reputation Points: 130
Solved Threads: 75
> from what i understand C++ is a subset of C
C++ is the functional superset of C.
> In reality I will need to know both.
Learning C++ should do the job. Like I said, since C++ is the functional superset of C, knowing C++ should as such make you proficient in C, though I am sure many people here would disagree with it. ;-)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
sub / super pshhh it was a typo
You just lived up to your name.. :)
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
> In reality I will need to know both.
Learning C++ should do the job. Like I said, since C++ is the functional superset of C, knowing C++ should as such make you proficient in C, though I am sure many people here would disagree with it. ;-)
You're right, there will be disagreement.
C and C++ have different mindsets. Knowing C++ you may know thesyntax of C, but because one is a procedural language and the other an OO language, knowing one does not necessarily give you the skills to write the other. At least not efficiently.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Thats why I specifically highlighted the term 'functional'. If you know C its just a matter of developing the OO mentality. Plus a good beginner book doesn't dwell on the OO part of the language but what can be achieved with the language.
Come to think of it, C++ is IMO not pure OO. It gives you the impression of OO features being added to an imperative language to make it a mainstream one (OO was the buzzword in those days).
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734