Why C++ Instead of C?
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
Well I mysellf am new to tech world but I think it depends upon feature that a particular language supports. To print something on screen you use - printf("The Sum is: %d", sum) in 'C'. But in C++, you dont have to worry about the datatype like - cout<<"The Sum is: "<< sum; So you see some laguages are easier to develop with. Moreover, almost anything that can be done in C++ can also be done in Java. But Java does not support pointers while C++ does. So does this make C++ a better / worse choice than Java? NO: it all depends on the problem that we are going to address and of course, our own choice as well.
-
Well I mysellf am new to tech world but I think it depends upon feature that a particular language supports. To print something on screen you use - printf("The Sum is: %d", sum) in 'C'. But in C++, you dont have to worry about the datatype like - cout<<"The Sum is: "<< sum; So you see some laguages are easier to develop with. Moreover, almost anything that can be done in C++ can also be done in Java. But Java does not support pointers while C++ does. So does this make C++ a better / worse choice than Java? NO: it all depends on the problem that we are going to address and of course, our own choice as well.
Any other answers?
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
IMHO, the most compelling reason to use C++ rather than C is 'classes', allowing Object Oriented Programming (OOP). Classes makes code more structured, easier to write, understand and maintain (and more stable). This is important, especially with complex applications. Polymorphism and other features are nice extras but I wouldnt say to choose C++ just for these features alone.
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
The advantage of
C++
overC
is Object Oriented Programming (OOP
).C++
supportsOOP
whileC
doesn't. That means you may write anOOP
application in a fair clean and elegant way usingC++
(you may write aC
application following theOOP
paradigms but your code would be more messy and your development time would be longer). It is worthy nothing thatOOP
is not a panacea: it is best suited for rather big projects (say more than100,000
lines of code) involving team of developers. Form smaller projects, in my opinion,OOP
is overkilling andstructured programming
(the paradigm supported by theC
language), is better.Veni, vidi, vici.
-
Any other answers?
pix_programmer wrote: Any other answers? Thats is rude. I dont think I am going to get paid for sharing my thoughts with "your excellency". ;P
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
in terms of program output, yes, C can do everything C++ does. but C++ makes OOP much easier.
-
pix_programmer wrote: Any other answers? Thats is rude. I dont think I am going to get paid for sharing my thoughts with "your excellency". ;P
-
overloaded Name wrote:
Thats is rude.
Actually that's not so rude, because your answer is apparently incomplete. ;P
Veni, vidi, vici.
but I think it depends upon feature that a particular language supports. Thats what I wrote in first line. I think I should have replaced this line with: "Features such as OOP". I just said a more generalize sentence. I assumed OP knew that C++ was named "C With Classes" at first, but was renamed later. CPallini wrote: Actually that's not so rude OK That is rude to some extent. Yet I confess my answer may have been incomplete and did not help, so no more replies from my side.
-
but I think it depends upon feature that a particular language supports. Thats what I wrote in first line. I think I should have replaced this line with: "Features such as OOP". I just said a more generalize sentence. I assumed OP knew that C++ was named "C With Classes" at first, but was renamed later. CPallini wrote: Actually that's not so rude OK That is rude to some extent. Yet I confess my answer may have been incomplete and did not help, so no more replies from my side.
-
The advantage of
C++
overC
is Object Oriented Programming (OOP
).C++
supportsOOP
whileC
doesn't. That means you may write anOOP
application in a fair clean and elegant way usingC++
(you may write aC
application following theOOP
paradigms but your code would be more messy and your development time would be longer). It is worthy nothing thatOOP
is not a panacea: it is best suited for rather big projects (say more than100,000
lines of code) involving team of developers. Form smaller projects, in my opinion,OOP
is overkilling andstructured programming
(the paradigm supported by theC
language), is better.Veni, vidi, vici.
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C) - All the things that performed by compiler you should do by yourself.(for example constructor - init, etc) Templates may be the thing - that really hard to performed - but generally macro can be used Why C++ Instead of C - some of the features realized and checked by compiler. but from the other side for C there are - small footprint,speed and etc. like assembler and C. At the end it is binary code.
-
Hi! I've been asked in an interview whether we could do all the things that were possible in C++ in C also. I answered Yes. But the interviewer further asked why C++ if you can do all the things in C itself(Constructor, Destructor, Polymorphism, Templates every thing is possible in C)? I don't know the answer. Can anybody explain?
C++ is an object oriented (OO) programming language. C isn't. OO has been widely accepted as a technological idiom hus it can be presumed to have merit. Arguments claiming it is popularity contest ignore the fact that there are many 'popular' technologies that have short runs and which are then abandoned or even outright condemned. So to the extent there is any objective criteria for picking a technology idiom OO seems to accepted as being better. Although one can program using OO in C it requires a great deal more manual attention to detail and additional code than doing it in C++. Both of those make it more likely that additional bugs will show up. Even more worrisome at lot of that additional code will involve pointers. And pointer bugs in C (and C++) are some of the more difficult bugs to find and thus cost more to fix. Of course one could just use structured programming rather than OO. Although having done OO for many years I find it extremely difficult to think in structured terms for anything more than trivial bits of code. And at one time I used to do structured programming so at least I know how to do it.
-
The advantage of
C++
overC
is Object Oriented Programming (OOP
).C++
supportsOOP
whileC
doesn't. That means you may write anOOP
application in a fair clean and elegant way usingC++
(you may write aC
application following theOOP
paradigms but your code would be more messy and your development time would be longer). It is worthy nothing thatOOP
is not a panacea: it is best suited for rather big projects (say more than100,000
lines of code) involving team of developers. Form smaller projects, in my opinion,OOP
is overkilling andstructured programming
(the paradigm supported by theC
language), is better.Veni, vidi, vici.
Agreed on pretty much anything, except that I consider 100,000 lines rather small, and don't see any advantage in using C over C++ on smaller projects, as long as there are at least two developers working on it. OOP and the stricter syntax of C++ is great for avoiding errors based on misunderstandings of code use.
-
Agreed on pretty much anything, except that I consider 100,000 lines rather small, and don't see any advantage in using C over C++ on smaller projects, as long as there are at least two developers working on it. OOP and the stricter syntax of C++ is great for avoiding errors based on misunderstandings of code use.
Stefan_Lang wrote:
Agreed on pretty much anything, except that I consider 100,000 lines rather small
Well
C
andC++
are pretty concise languages. Of course you may feel100,000
'small' (I feel it 'large'), however, probably10^5
is the right order of magnitude.Stefan_Lang wrote:
and don't see any advantage in using C over C++ on smaller projects, as long as there are at least two developers working on it. OOP and the stricter syntax of C++ is great for avoiding errors based on misunderstandings of code use.
I think structured programming is better than OOP for small projects. You may use
C++
(as 'betterC
') with the structured programming paradigm, of course.Veni, vidi, vici.