C How Much Different From C++?

This is a discussion on C How Much Different From C++? within the C++ Programming forums, part of the General Programming Boards category; alright i got a book from the library and it is c programming because the C++ programming books were out. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    32

    Post C How Much Different From C++?

    alright i got a book from the library and it is c programming because the C++ programming books were out. how much different is c from c++ do you think i could use this book?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    c and c++ are exactly the same

    all c programs should work in c++

    c++ is an extension of c

    c++ programs may not work in c, though.

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    C and C++ are not exactly the same. But they are very similar.
    They share the same general programming contructs. The way I/O is handled and dynamic memory allocation is different. C++ also has classes which are similar to structs. If you learn C it's a quick move to C++ and people that learn C++ first can quickly pick up the way C does things.
    You should be just fine learning C first and then picking up the additional C++ concepts later.

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    they are pretty much the same except for polymorphism(at least thats what I think) and use different functions that do the same thing.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    and the dynamic memory is different

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    do u mean the calls (new instead of malloc) or the actual way it is handled?

    (I never learned C)

  7. #7
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    The dynamic memory of C++ allows you to control the life time of the variables, whatever its global or auto.On the counter of C , where you cant control the life time (e.g. global variable ll be in the memory as long as your program is running)

    these features are allowed by using (new, delete)
    you can use -delete- also to delete an array which you should do in C using memset

    Another difference is the fact that many words are preserved in C++ as keywords , while it was available as identifier in C (e.g. friend, this )

    However , I think you can begin with C++ then C ll look almost the same for you.

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    How hard would it be to go the other way? I already know C and I'm trying to learn C++(through tuts cuase Im cheap and dont want to buy books) but I am having some problems with the threory behingd classes which as far as I know are like structures except they can also have functions ad part of them where as structures cant(am I correct?). Anyway I'm rambling and but to get to the point how hard should I expect C++ to be to learn if I already know C?
    "Christ died for our sins. Dare we make his martyrdom meaningless by not committing them?"

  9. #9
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    Class = Structure + Private Data

  10. #10
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    A struct can hold function definitions also, although it usually doesn't.

    Classes are just encapsulations of your functions and variables into logical objects. Structs and Classes are very similar except Classes can be inherited, derived from and the security levels can be set. A struct is completly public so you can call a variable inside it from any function, but a Class can have it's variables and functions set to private so only the class can have access to them and no outside functions can gain access to them.

    Syntax wise C and C++ are almost exactly the same but C++ is all about the Classes so you are gonna need a book on it to learn about that, once you know classes you know C++. The rest is API calls, logic, and proficiency.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    12
    The difference between C and C++ is that C++ is the better C.

  12. #12
    Unregistered
    Guest
    to my knowledge structs in C can only hold variables, but not functions. Also the keyword struct needs to be used when declaring instance of the struct, unless the instance is declared immediately after the struct declaration.

    structs in C++ are the same as classes except that all members (variables or functions) are public by default whereas in classes all members are private by default. By convention, most people use structs in C++ similar to what structs in C are--usually they don't have structs contain functions, usually they don't inherit from structs, usually they don't have structs contain private or protected members--- but it is convention, not requirements. When using structs in C++ you don't need to use the keyword struct except in the initial declarations.

    classes are not available in C which means data tends to be more exposed and there is no inheritance, so code tends to be more redundant. There is also better type checking in C++ than in C (one of the weaknesses or benefits, depending on your point of view, with printf()). Given availability of classes, you can get a better modeling of the unvierse you are trying to recreate in code using C++ vs C (although even then it's not perfect).

    As previously mentioned there are more keywords in C++, the method of I/0 differs between C and C++, and (just about)everything you do in C you can do in C++, but not visa versa.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21