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?
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?
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.
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.
they are pretty much the same except for polymorphism(at least thats what I think) and use different functions that do the same thing.
and the dynamic memory is different
do u mean the calls (new instead of malloc) or the actual way it is handled?
(I never learned C)
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.
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?"
Class = Structure + Private Data
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..."
The difference between C and C++ is that C++ is the better C.
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.