Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why C++ Instead of C?

Why C++ Instead of C?

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpfoopquestioncareer
15 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pix_programmer
    wrote on last edited by
    #1

    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?

    A S CPalliniC C U 6 Replies Last reply
    0
    • P pix_programmer

      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?

      A Offline
      A Offline
      AmbiguousName
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • A AmbiguousName

        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.

        P Offline
        P Offline
        pix_programmer
        wrote on last edited by
        #3

        Any other answers?

        A 1 Reply Last reply
        0
        • P pix_programmer

          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?

          S Offline
          S Offline
          softwaremonkey
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P pix_programmer

            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?

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            The advantage of C++ over C is Object Oriented Programming (OOP). C++ supports OOP while C doesn't. That means you may write an OOP application in a fair clean and elegant way using C++ (you may write a C application following the OOP paradigms but your code would be more messy and your development time would be longer). It is worthy nothing that OOP is not a panacea: it is best suited for rather big projects (say more than 100,000 lines of code) involving team of developers. Form smaller projects, in my opinion, OOP is overkilling and structured programming (the paradigm supported by the C language), is better.

            Veni, vidi, vici.

            In testa che avete, signor di Ceprano?

            L S 2 Replies Last reply
            0
            • P pix_programmer

              Any other answers?

              A Offline
              A Offline
              AmbiguousName
              wrote on last edited by
              #6

              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

              CPalliniC 1 Reply Last reply
              0
              • P pix_programmer

                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 Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #7

                in terms of program output, yes, C can do everything C++ does. but C++ makes OOP much easier.

                image processing toolkits | batch image processing

                1 Reply Last reply
                0
                • A AmbiguousName

                  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

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  overloaded Name wrote:

                  Thats is rude.

                  Actually that's not so rude, because your answer is apparently incomplete. ;P

                  Veni, vidi, vici.

                  In testa che avete, signor di Ceprano?

                  A 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    overloaded Name wrote:

                    Thats is rude.

                    Actually that's not so rude, because your answer is apparently incomplete. ;P

                    Veni, vidi, vici.

                    A Offline
                    A Offline
                    AmbiguousName
                    wrote on last edited by
                    #9

                    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.

                    CPalliniC 1 Reply Last reply
                    0
                    • A AmbiguousName

                      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.

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #10

                      Don't get offended. I was joking, after all. However introducing iostreams like one of major C++ achievements it is a common mistake.

                      Veni, vidi, vici.

                      In testa che avete, signor di Ceprano?

                      1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        The advantage of C++ over C is Object Oriented Programming (OOP). C++ supports OOP while C doesn't. That means you may write an OOP application in a fair clean and elegant way using C++ (you may write a C application following the OOP paradigms but your code would be more messy and your development time would be longer). It is worthy nothing that OOP is not a panacea: it is best suited for rather big projects (say more than 100,000 lines of code) involving team of developers. Form smaller projects, in my opinion, OOP is overkilling and structured programming (the paradigm supported by the C language), is better.

                        Veni, vidi, vici.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Spot on answer. 5!

                        ============================== Nothing to say.

                        1 Reply Last reply
                        0
                        • P pix_programmer

                          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?

                          U Offline
                          U Offline
                          User 1985
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • P pix_programmer

                            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?

                            J Offline
                            J Offline
                            jschell
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • CPalliniC CPallini

                              The advantage of C++ over C is Object Oriented Programming (OOP). C++ supports OOP while C doesn't. That means you may write an OOP application in a fair clean and elegant way using C++ (you may write a C application following the OOP paradigms but your code would be more messy and your development time would be longer). It is worthy nothing that OOP is not a panacea: it is best suited for rather big projects (say more than 100,000 lines of code) involving team of developers. Form smaller projects, in my opinion, OOP is overkilling and structured programming (the paradigm supported by the C language), is better.

                              Veni, vidi, vici.

                              S Offline
                              S Offline
                              Stefan_Lang
                              wrote on last edited by
                              #14

                              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.

                              CPalliniC 1 Reply Last reply
                              0
                              • S Stefan_Lang

                                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.

                                CPalliniC Offline
                                CPalliniC Offline
                                CPallini
                                wrote on last edited by
                                #15

                                Stefan_Lang wrote:

                                Agreed on pretty much anything, except that I consider 100,000 lines rather small

                                Well C and C++ are pretty concise languages. Of course you may feel 100,000 'small' (I feel it 'large'), however, probably 10^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 'better C') with the structured programming paradigm, of course.

                                Veni, vidi, vici.

                                In testa che avete, signor di Ceprano?

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups