Difference between C and C++


1. C is a procedure or function oriented language whereas  C++ is a Object oriented     language.

2. C has top down approach whereas C++ has a bottom up approach.

3. In C++ new and delete operators are used to allocate and free memory but in C malloc() and free() functions are used for allocation and freeing memory.

4. In C++ prototype of a function have to be defined before using it but in C functions can be used without defining a prototype.

5. Structures of C++ can have functions in them but C structures can only have variables.

6. For I/O C++ has iostream.h and C has stdio.h.

7. Function overloading is allowed in C++ but functions in C does not support overloading.

8. In C we have to include the struct keyword before the name of the structure to declare a instance of a structure. In C++ only the structure name is required. Example - :
      
         struct  employee
        {
           int id;
           char *name;
           // other variables
        };     

         //Statement to declare structure variable in C
         struct  employee  e1;      

         //Statement to declare structure variable in C++
         employee  e1;      


main() doesn’t add  return 0 statement automatically in C. In C++ it provide this statement.
  
//In C++ return 0 is added automatically.  
     int main()
       {
             printf(“Hello How are you”);
        }

//In C return 0 has to be added manually.  
     int main()
       {
             printf(“Hello How are you”);
             return 0;
        }
  
9. C allows a void* pointer to be assigned to any pointer type without a cast, whereas C++ does not
10. Enumeration constants  are always of type int in C, whereas they are distinct types in C++ and may have size different from that of int.
11.C++ identifiers are not allowed to contain two or more consecutive underscores in any position. C identifiers are not allowed to start with two or more consecutive underscores, but may contain them in other positions

12. C allows structunion, and enum types to be declared in function prototypes, whereas C++ does not.