You are on page 1of 3

Difference between C & C++

1-C was the C++ predecessor. As it's name implies, alot of C remains in C++. Although not actually being more powerful than C, C++ allows the
programmer to more easily manage and operate with Objects, using an OOP (Object Oriented Programming) concept.

C++ allows the programmer to create classes, which are somewhat similar to C structures. However, to a class can be assigned methods, functions
associated to it, of various prototypes, which can access and operate within the class, somewhat like C functions often operate on a supplied handler
pointer.

Although it is possible to implement anything which C++ could implement in C, C++ aids to standarize a way in which objects are created and managed,
whereas the C programmer who implements the same system has alot of liberty on how to actually implement the internals, and style among
programmers will vary alot on the design choices made.

In C, some will prefer the handler-type, where a main function initializes a handler, and that handler can be supplied to other functions of the library as
an object to operate on/through. Others will even want to have that handler link all the related function pointers within it which then must be called using
a convention closer to C++.

To finish this discussion, C++ applications are generally slower at runtime, and are much slower to compile than C programs. The low-level infrastructure
for C++ binary execution is also larger. For these reasons C is always commonly used even if C++ has alot of popularity, and will probably continue to be
used in projects where size and speed are primary concerns, and portable code still required (assembly would be unsuitable then).

2. The C differ from c++ in these things :


1 the in put /out put in the c ( use printf , for the out and scanf for the input )
2 in c use #include<stidio.h> , but in the c++ use #include <iostream>
3 in the c CAN NOT use the string type but you can declear it as an array
4 also there are some deffereant in function how write the function and how to call the function.

3. The main difference between C & C++ is the OOPS technology, C++ is an object oriented programing language, using which one can program using
the objects that are been created. C++ have the provision of inheritence, constructors whereas you will not find these in C.
Still C is better then C++ because of its easy and understable syntax !!!
4. C++ on the other hand is mainly used in large projects of millions of lines of code, where C code would become unmaintainable. This is mainly due to
the possibility to reuse existing code by exploiting the OOP concepts of polymorphism and inheritance.
5. c++ is extension of c. c++ is super set of c.
the most important feature of C++ is that it is object oriented language.But there are some basic changes made in c++.
for example in c if function don't pas any parameter u have to explicitly write void in brackets.but in c++ you don't need to write.
6. The main difference between C and C++ is that C isn't object-oriented. Okay---that doesn't actually tell you what you want to know; here are some
details:
structs don't copy in C. That is, if a and b are structs then the line a = b; doesn't work. Nor will structs be fed into functions as arguments. The only way
to deal with them sensibly is to use pointers to them, or to write functions to copy their elements explicitly. classes (with private members) don't exist in
C.
There is no operator and function overloading in C. If a function has a name, then that's it---you can't have another version with the same name that
does the same thing with different arguments, as you can in C++. The fact that << and >> (left and right shift) do output and input in C++ is a
consequence of the ability of the language to overload those operators. Output and input in C are handled by functions called printf and scanf
respectively (these also work in C++ if you want, of course).
In C storage allocation and de-allocation are not handled by new and delete but by a function called malloc. In general, the whole process is a bit more
messy in C, but is not too bad once you get the hang of it.
7. C is procedure oriented language and c++ is object oriented language.In c there will be much more code redundancy,which is almost eliminated in c+
+ through inheritance and extra functionality can be appended easily in case of c++ program than in c.The main thing i like in c++ is data hiding which
can't be done in c.I feel c++ is much more reliable than c.
8. The first major difference between C and C++ is that C is a POP(Procedure Oriented Programming) Language whereas C++ is a OOP.
C uses Top Down aproach and focuses on procedures.Data moves as such
Whereas C++ uses bottom up approach and focuses on data(Data hiding,Abstaction)
Dyanimic memory allocation in C by calloc() and malloc() In C++ by new and delete.
C recognizes only first 32 char of string whereas C++ do not pose this limit.
Prototyping is optional in C mandatory in C++
main() may not have a return type in C but return type mandatory in C++
We can assign a void pointer to a non-void pointer in C .No such concept in C++
void *ptr1="vaibhav";
char *ptr2="Vai"
ptr2=ptr1 // valid in C
9. c is a middle level language having both features of low level and high level language.its a structured and top down approach programming language.
c++ is a high level language because of its oops implementation.its object oriented programming language.
c has uses structures to bind data and data members but c++ uses Classes.
c has the limited reusability.
c++ extends its reusability with c++.
in C++ data can be represented as live entities with thier name as identifiers and reuse it.
for standard input and output functions , c uses stdio.h header file and in c++ uses iostream.h.
Function prototyping is optional in c.
Functional prototyping is compulsion in c++.
Data hiding is possible with features of classes and its access specifiers.
10. To me not only is C++ a "work smarter, not harder" kind of thing... It at'sa lot of very usefull features including classes, that are helpful even to the
novice programmer. For one the cin and cout classes are king over C's input methods.
C++:
cout << "Enter two integers seperated by spaces: ";
cin >> x1 >> x2;

C:
printf("Enter two integers seperated by spaces: ");
scanf("%i %i", &x1, &x2);
The cin can be tested for a bool value in if, while, do-while and for...

int x;
cout << "Enter an integer:";
if (cin >> x) //Tries to assign input to x, fails if input cannot be converted to int.
cout << "That wasn't an int"
11. The main difference between c and c++ is that c is procedural language where as c++ is a object oriented language,c++ differs in OOPS concept
from c,
2)--Other than this C++ uses const data,friend function,
3)--c++ structure can contain member function where c structure can not.
4)--The datatype typecast is different in c and c++.e.g(int i=50;float f=(float)i;will convert i int to float)but in c++(int i=50;float f= float (i);).
5)--Other differences are c++ uses its string Datatype where c does not,Boundary checking of array is not in c but in c++ .
6)--Exception handling is done in c++ but not in c.
7)--the input/output operation is done in c++ through cout and cin objects but in c it is done through printf() and scanf() functions..
13. 1. C source code file name should be *.c and *.h for implement file and header file.

2. Variables reference is not supported, so you should not use it in C.

3. Structure definition is not the same in C++ and C

4. new and delete operator is not supported in C, you should use malloc and free c function to replace it.

5. In C, you cannot use template and template class.

6. From C++ to C, you should exclude every STL, ATL, COM, MFC functions, classes usage. You should write your own code to replace the above
functionality.

7. In C, variable definition lies in the beginning of each function, whereas C++ you can put variable definition wherever you want. Therefore, You should
move all variable definition that doesnt lie in the beginning of each function to the beginning.

8. Class is not supported in C, so you should convert all of class definition in C++ to structures and functions in C. You should also know there have
automatic initialization and releasing resource procedure in C++ as constructor and destructor implementation but C has not. The following is a rule to
port:

9. The sizeof keyword gives the amount of storage, in bytes, associated with a variable or a type. In C, in default environment setting, sizeof returns the
actual size include padding bytes inserted for alignment, whereas C++ doesnt. So you should be very carefully about this situation.

10. The int type is not a hardware-independent type. You should know, in 16-bit system such as Windows 3.1 environment, sizeof(int) = 2, whereas in
32-bit system such as Windows 2000 & XP, sizeof(int) = 4. Therefore, in C, you should try your best not use int. You can use long (4 Bytes) or short (2
Bytes). This is a critical problem especially for file read and write.
14. C++ is actually an extension of C. It supports OOPs concepts. But all these OOPs concepts can be implemented in C. But its the programmers'
responsibility to do this in C. But in C++, the language has built-in capability to support OOPs concepts through classes. Most of the C programs will
compile under C++ with/without some warnings. The main advantage of C++ is its maintainability and code reuse and sharing. Again code reusing and
sharing can be done in C also but its programmers responsibility. C++ provides facilities through inheritance.
In syntax point of view there are some differences but the syntax of C are valid in C++, of course it may show some warning message. For example, for
type conversion,
in C, it should be given as
(type)variable
but C++ allows function like style as
type(variable).

The decision to follow C or C++ is upto the programmer and the project which is to be done.
15. Main diff bet C and C++ are as follows,
C++ supports OOPS concepts, C doesn't
C++ supports inheritance, C doesn't
C++ supports constructors , C doesn't
C++ hard to code, but C is easy to code
16. C was originally written as a language that was as powerful as assembly but is also portable to other platforms. There is a common realm of thought
that if the PDP-11 had supported "XCHG" instructions, we'd see them as operators in C.

C++ actually evolved from C so those who say "it's another language entirely" are not correct in my opinion. Original C++ compilers actually generated
C code. Infact, C++ grew from the field as people used C++ in absurd and obscure ways those obscurities actually made it into the language as
standards! No matter how bad the programming methodology was!

This is C++'s fatal flaw, being backwards compatible with C. The flexiblity of C, essentially a "macro assembler" which "high level constructs". This
doesn't make for good voodoo! As a high level language it provides a more rigid interface and hard to expand model. The implicit operations of C++
also make it harder to read, harder to maintain and harder to figure out exactly wtf the scope of something is.

They state that C++ is "OO" however, C can be written as OO as well. OO is not langauge syntax but rather how the design is constructed. Just
because you use "class" doesn't automatically make your code, "OO" which is another common mistake. Actually, if you can't understand how to do
"OO" in C, you actually shouldn't be writing it in C++ because you definately don't understand "OO"!!!!!

C++ has lots of bad things such as pass by reference, operator overloading, multiple inheritence and copy constructors. One of the main goals of an
"abstraction" is just that. The user doesn't need to know the details of how it was implemented to use it. Unfortunately, this is not the case with C+
+. You NEED to know how it was implemented in order to use it. For example, is that implicit copy constructor a shallow or deep copy? I better know
before I pass anything by value! What the hell does the "+" do? By the function name, I really have no idea. Will "-" work on the same data? I'd rather
see a function descriptive NAME rather than a + or - if it's not a real mathematical operation.

Functions and variables are hard to scope. If you see them in a class you have no idea where they came from. Are they global? Are they in some nth
inherited class? How about classes that reuse function names of real functions? Hard to track down what one is being used and you could make
mistakes!

What about ease of implementation? Arrays can be dangerous with polymorphism! Typecasting back to a base class and indexing will cause corruption
of data!!! AND THIS COMPILES FINE! Now to write a simple array you have to write hundreds of lines of code to do something so simple. So there's
trade offs, to do something simple you need to write tons of code!

C is easier to read and understand. There are less keywords to make it simpler to optimize and figure out what's going on. If you consider that people
can write bad C code and C++ includes C and more, then obviously C++ is a disaster waiting to happen because you have all the bad habits that can
occur in C (from a few simple keywords) to everything new that you can do (a ton of complex, hard to read and understand functionalities and implicit
operations).

All in all, if you want high level constructs, use a high level language like Java or C#. If you want lower level constructs, use C or assembly if need
be. However, never use C++!!!!!!!!!

You might also like