HomeTECH ARTICLES

Difference Between C and C++ Programming Languages

Difference Between C and C++ Programming Languages
Like Tweet Pin it Share Share Email

 

Let’s learn the major differences between C and C++ programming languages i.e. C vs. C++. It is one of the most commonly asked questions in technical interviews.

c-and-c-differences-comparison

Origins of C and C++

Dennis Ritchie of the Bell Labs designed the C, a general purpose computer programming language in 1972 for use with UNIX, an operating system of then. C is predominantly used for system software programming but is also very useful for creating general application software.

C++(originally named “C with Classes” and still known as the superstructure of C in computer circles) was developed as an enhancement of C by Bjarne Stroustrup in 1983 at the Bell Labs.

Usage of C vs. C++

  • C proved very useful in running applications coded in assembly language because of its strengths like a simple compiler, lower access levels of memory, lower run time support and an efficient constructing language that was in sync with the hardware instructions.
  • Another of its credits is that it is a highly portable (compatible with a variety of OS & Platforms) with very minimal source code changes required.

 

  • C++ is known as a mid-level language. Due to the fact that the C++ comprises of both high-level and low-level language features. Some of the adjectives used to describe C++ are static typed, free-form, multi-paradigm and supporting procedural programming.

 

Major differences between C and C++

# C C++
1 C is a procedural (aka structural) programming language. In addition to begin procedural, C++ is also an object oriented programming language.
 2 In C language, the solution is achieved through a sequence of procedures or steps. Therefore, C is a function driven language. C++ can model the whole solution in terms of objects and that makes the solution better organized. C++ is an object driven language.
 3 Concept of virtual functions is not present in C. C++ offers the facility of using virtual functions.
 4 Operator overloading is not possible in C. C++ allows operator overloading.
 5 Data in C functions is not secured. Data can be easily accessed by other external functions. All the data in C++ can be put inside objects. This provides better data security.
 6 C is a middle level language. C++ is a high level language.
SEE ALSO: Difference between C++ and Java
 7 C programs are divided into modules and procedures. C++ programs are divided into classes and functions.
 8 C programs use top-down approach. C++ programs use bottom-up approach.
 9 In C, the main() function can be called from other functions. In C++, the main() function can not be called from other functions. The program execution begins from main() function.
 10 C language does not provide the feature of namespace. Namespaces are available in C++.
 11 Exception handling is not easy in C. It has to be done by using other functions. C++ provides exception handling through Try and Catch block.
 12 Inheritance is not possible in C. Because C++ is an object oriented language, inheritance is possible.
 13 In C, all the variables must be declared at the beginning of a scope. C++ allows declaring variables anywhere within the scope. This allows us to declare a variable when we use it for the first time.
 14 In C, function overloading is not possible. Function overloading is to use two functions with the same name within a scope. Function overloading is possible in C++
 15 Standard Input in C is received through scanf() function whereas standard output is given through printf() function. C++ uses cin>> and cout>> as standard input and output functions respectively.
 16 C programs are saved in files with extension .c C++ programs are saved in files with extension .cpp
 17 Mapping between data and functions is difficult in C. In C++ data and functions are easily mapped through objects.
 18 In C, polymorphism is not possible. Being a fully object oriented language, C++ offers polymorphism.
 19 C supports only built-in data types. C++ supports both built-in and user-defined data types.

 

Language Characteristics

 

Characteristics of C

Some of the important characteristics of C are as follows:

  1. Structured programming facilities
  2. Confirming to the ALGOL traditions
  3. Short circuit evaluation – usage of only one operand if the result can be determined with it alone
  4. Static typing system for avoiding unintended operations
  5. Value passed parameters with relevance to pointer value passing
  6. Heterogeneous data combination & manipulation
  7. Reserved keywords and free-format source text
  8. Larger number of compound operators, such as +=, ++
  9. Huge variable hiding capacity, though function definitions being non-nestable
  10. Character – integer usage similar to assembly language
  11. Low-level access to computer memory via machine addresses and typed pointers
  12. Function pointers allow rudimentary forms of closures & polymorphic runtime
  13. Pointer arithmetic defined Array indexing (secondary notion)
  14. Standardized processor for defining macros, including source code files & conditional compilations
  15. Complex Input/Output and mathematical functions with consistent delegation to library routines
  16. Syntax same as “B” (C’s predecessor) but different from ALGOL e.g.: { … } replaced begin … end, && and || replaced and & or, which
  17. While B used & and | in both meanings, C made them syntactically distinct from the bit-wise operators
  18. Similarities to Fortran e.g: the equal- sign for assignment (copying) & two consecutive equal-signs to test for equality (compare to EQ) or the equal-sign in BASIC)

 

Characteristics of C++

  1. C++ is designed to be a statically typed, general-purpose language that is as efficient and portable as C
  2. C++ is designed to directly and comprehensively support multiple programming styles (procedural programming, data abstraction, object-oriented programming, and generic programming)
  3. C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
  4. C++ is designed to be as compatible with C as possible, therefore providing a smooth transition from C
  5. C++ avoids features that are platform specific or not general purpose
  6. C++ does not incur overhead for features that are not used
  7. C++ is designed to function without a sophisticated programming environment

 

[SOURCE]

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *