Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: difference between c and c++

  1. #1
    Join Date
    Oct 2007
    Location
    USA
    Beans
    354

    Question difference between c and c++

    hey,

    What is the major difference between c and c++? and is it possible for me to learn c++ without learning c first?

    Thanks
    Think carefully before just copying and pasting the commands your are advised into your terminal and clicking Enter, for more information about which ones not to use see this: http://ubuntuforums.org/announcement.php?f=73

  2. #2
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: difference between c and c++

    1) C++ supports object-oriented programming in the language, C does not
    2) Yes you can learn C++ without having prior C knowledge, anyway if you learn C++ you will learn C basics along the way because C++ is based on C

  3. #3
    Join Date
    Oct 2007
    Location
    USA
    Beans
    354

    Question Re: difference between c and c++

    And what are the major usage of c++? c? And which one do u suggest i go with?
    Think carefully before just copying and pasting the commands your are advised into your terminal and clicking Enter, for more information about which ones not to use see this: http://ubuntuforums.org/announcement.php?f=73

  4. #4
    Join Date
    Nov 2007
    Beans
    88
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: difference between c and c++

    C++ in my opinion. Namely due to OOP allowing for more modular coding and a quicker crossover to other languages.

    Also In my opinion, if you know C++ you can do C aswell.

  5. #5
    Join Date
    Apr 2007
    Beans
    14,781

    Re: difference between c and c++

    Quote Originally Posted by iharrold View Post
    Also In my opinion, if you know C++ you can do C aswell.
    If you mean learning the syntax of C, then that is true.

    C and C++ are difference languages, although many say that C is a subset of C++, I do not think that is true.

    C is a very simple language; C++ can be confusing, but isn't complicated either.

  6. #6
    Join Date
    Jul 2006
    Beans
    Hidden!

    Re: difference between c and c++

    I personnaly prefer C++. Even if you don't use the advanced features, being able to use stuff like namespaces, and using new/delete instead of malloc/free are IMO worth it.
    Also, most big projects are written with OOP or at least with OOP-like techniques. It takes time to master but IMO OOP is a big plus

    (some people say they don't like OOP, but in many cases - though not all - it's just because they don't master it. the main reason for going with C instead of C++ is simplicity)

  7. #7
    Join Date
    Aug 2007
    Beans
    219

    Re: difference between c and c++


  8. #8
    Join Date
    Oct 2007
    Location
    USA
    Beans
    354

    Re: difference between c and c++

    I pasted this command in gedit:

    #include<iostream>
    using namespace std;

    int main(void)
    {

    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    cout<< "please enter 3 numbers!";<< endl;
    cin>> dnumber1;
    cin>> dnumber2;
    cin>> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) /3;
    cout<< "the average of the numbers are: "<< daverage << endl;

    return 0;
    }

    and saved it as "c++.cpp"

    Then when i tried to run it thru terminal this is what it said:

    limac@limac-ubuntu:~$ cd ~/Desktop
    limac@limac-ubuntu:~/Desktop$ g++ -o c++ c++.cpp
    c++.cpp: In function ‘int main()’:
    c++.cpp:12: error: expected primary-expression before ‘<<’ token
    limac@limac-ubuntu:~/Desktop$

    What went wrong???
    Think carefully before just copying and pasting the commands your are advised into your terminal and clicking Enter, for more information about which ones not to use see this: http://ubuntuforums.org/announcement.php?f=73

  9. #9
    Join Date
    Apr 2007
    Beans
    14,781

    Re: difference between c and c++

    Quote Originally Posted by limac View Post
    I pasted this command in gedit:

    #include<iostream>
    using namespace std;

    int main(void)
    {

    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    cout<< "please enter 3 numbers!" << endl;
    cin>> dnumber1;
    cin>> dnumber2;
    cin>> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) /3;
    cout<< "the average of the numbers are: "<< daverage << endl;

    return 0;
    }
    You can had an extra semi colon.

  10. #10
    Join Date
    Oct 2007
    Location
    USA
    Beans
    354

    Re: difference between c and c++

    where was that?
    Think carefully before just copying and pasting the commands your are advised into your terminal and clicking Enter, for more information about which ones not to use see this: http://ubuntuforums.org/announcement.php?f=73

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •