what is the main difference between c and c++?
Answer Posted / ravi kumar martha
1. C is a general programming language. C++ is an Object
Oriented variant of C.
2.C++ was based on C and retains a great deal of the
functionality.
C++ does not retain complete source-level compatability
with C.
3.
In C, there's only one major memory allocation function:
malloc. You use it to allocate both single elements and
arrays and you always release the memory in the same way.
In C++, however, memory allocation for arrays is somewhat
different than for single objects.
you use the new[] operator, and you must match calls to new
[] with calls to delete[] (rather than to delete).
4.Although most good C code will follow this convention, in
C++ it is strictly enforced that all functions must be
declared before they are used. This code is valid C, but it
is not valid C++.
5.You have to include the struct keyword before the name of
the struct type to declare a struct: In C++, you could do
this, and have a new instance of a_struct called
struct_instance. In C, however, we have to include the
struct keyword when declaring struct_instance
6.you must include the keyword enum; in C++, you don't have
to. As a side note, most C programmers get around this
issue by using typedefs.
7.C++ has a much larger library than C, and some things may
be automatically linked in by C++ when they are not with C.
For instance, if you're used to using g++ for math-heavy
computations, then it may come as a shock that when you are
using gcc to compile C, you need to explicitly include the
math library for things like sin or even sqrt.
8.C does not provide a native boolean type. You can
simulate it using an enum, though.
9.In C++, you are free to leave off the statement 'return
0;' at the end of main; it will be provided automatically.
| Is This Answer Correct ? | 15 Yes | 9 No |
Post New Answer View All Answers
What is abstraction in oops?
Write a program to sort the number with different sorts in one program ??
What is interface in oop?
What is class and object in oops?
How does polymorphism work?
Get me a number puzzle game-program
What is a superclass in oop?
Templates mean
What polymorphism means?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
What is static modifier?
What is the purpose of polymorphism?
Can bst contain duplicates?
Can a varargs method be overloaded?
Can main method override?