A COMPARATIVE ANALYSIS OF C AND C++
COURSE TITLE: STRUCTURED PROGRAMMING
COURSE CODE: 301
BY
NANJI EMMANUELLA LAKAN
(U21CS1031)
TABLE OF CONTENTS
TABLE OF CONTENTS................................................................................................................ 2
HISTORY...................................................................................................................................... 2
1.1 INTRODUCTION.....................................................................................................................3
1.1.0 PROGRAMMING LANGUAGES................................................................................3
1.1.1 DEFINITION OF PROGRAMMING LANGUAGES...................................................3
1.1.2 BRIEF HISTORY OF PROGRAMMING LANGUAGES............................................3
1.2 C................................................................................................................................................4
1.2.1 HISTORY OF C.............................................................................................................4
1.3 INTRODUCTION TO C++......................................................................................................5
1.3.1 HISTORY......................................................................................................................6
1.3.2 C with Classes provided:................................................................................................6
LANGUAGE DESIGN PRINCIPLES AND PARADIGMS...........................................................8
2.1 DESIGN PRINCIPLES.............................................................................................................8
1.2.1 Programming Language Design.....................................................................................8
1.2.2 Factors to be Considered When Designing A Programming Language..........................8
2.2 Programming Paradigms.........................................................................................................10
2.2.1 What are Programming Paradigms...............................................................................10
2.3 and Limitations.......................................................................................................................12
2.3.1 Uses of C and it’s Limitation.......................................................................................12
2.3.2 Features of C++ not Readily Available in C.................................................................14
REFERENCE............................................................................................................................... 16
2
HISTORY
1.1 INTRODUCTION
1.1.0 PROGRAMMING LANGUAGES
There would be no better introduction to any programming language without talking
about the history of programming languages, especially before the times of our
subjects of discussion, being C and C++. Talking about programming languages is a
greatly exhaustive topic, so I would try to keep it brief.
1.1.1 DEFINITION OF PROGRAMMING LANGUAGES
Slightly modifying the definition given by (Daragh Ó Tuama.(2023)), A
Programming Language is a computer language that programmers use to write
instructions, develop programs, and write scripts that direct the computer on how to
do certain tasks or groups of tasks.
1.1.2 BRIEF HISTORY OF PROGRAMMING LANGUAGES
Though every programming language has a similar interface, which is to allow the
programmers to write instructions, every program has its own syntax, a set of rules
that guide the programmer on how to interact with the machine via this syntax.
According to (Sanjay K M. ( 2023)) The term Programming dates back to the early
19th century and even farther when mathematician Ada Lovelace created an
algorithm for Charles Babbage's Analytical Engine, which is considered the first
computer. However, the first actual programming language was developed in the
3
1950s, called FORTRAN (Formula Translation). This language was used for
scientific and engineering calculations. By the 1960s, programming languages such as
COBOL (Common Business-Oriented Language), BASIC (Beginners All-Purpose
Symbolic Instruction Code), and ALGOL (Algorithmic Language) were developed.
ALGOL
The father of programming languages to some is said to be ALGOL, first introduced
in 1960. ALGOL (Algorithmic Language) was initially used significantly in European
countries, and it introduced the concept of structured programming to the people. In
1967, a new programming language came into force called ‘BCPL’, meaning Basic
Combined Programming Language. And now With the Introduction of ALGOL, we
can now venture into the history of C.
1.2 C
1.2.1 HISTORY OF C
(Upgrad.com.) discusses the history of C as a language that inherited its foundational
design from the ALGOL tradition, and before C, BCPL existed and was designed and
developed as a general-purpose programming language by Martin Richards. After
three years, another programming language was introduced in 1970 by Ken
Thompson. It was known as ‘B’, which combined various features of ‘BCPL’. It was
created using the UNIX operating system at AT&T and Bell Laboratories. In 1972, C
was developed by Dennis Ritchie and Ken Thompson at the Bell Laboratories, created
from ‘ALGOL’, ‘BCPL’, and ‘B’. ‘C’ contains all these languages and much more,
making it unique from the other programming languages. The origin of C is closely
tied to the development of the Unix operating system, originally implemented in
4
assembly language on a PDP-7 by Dennis Ritchie and Ken Thompson, incorporating
several ideas from colleagues. So Thompson wanted a programming language for
developing utilities for the new platform. Initially, he tried to write a Fortran
compiler, but soon gave it up as it wasn't giving the desired results. Instead, he created
a cut-down version of BCPL, which was still relatively new at the time. Thompson
modified the syntax to be less wordy, and similar to a simplified ALGOL known as
SMALGOL. Thompson called the result B. He described B as "BCPL semantics with
a lot of SMALGOL syntax. Like BCPL, B had a bootstrapping compiler to facilitate
porting to new machines. However, few utilities were ultimately written in B because
it was too slow and could not take advantage of PDP-11 features such as byte
addressability. In 1971, Ritchie started to improve B, to utilize the features of the
more powerful PDP-11. A significant addition was a character data type. He called
this New B (NB). Thompson started to use NB to write the Unix kernel, and his
requirements shaped the direction of the language development. Through to 1972,
richer types were added to the NB language: NB had arrays of int and char. Pointers,
the ability to generate pointers to other types, arrays of all types, and types to be
returned from functions were all also added. Arrays within expressions became
pointers. A new compiler was written, and the language was renamed C. Initially, ‘C’
was limited to UNIX OS, but it gradually spread worldwide, and many compilers
were released for cross-platform systems. But Just Like many things in the evolution
of Programming and Programming Languages, the C programming language had its
constraints, and that’s when C++ and many other languages come in.
1.3 INTRODUCTION TO C++
5
1.3.1 HISTORY OF C++
According to (Frank van den Beuken. 2023) C++ was developed by a Danish
computer scientist Bjarne Stroustrup at AT&T Bell Labs in 1979, seven years after
the introduction of C. Its origin stemmed from Bjarne’s analysis of the UNIX kernel
to investigate to what extent it can be distributed over a network. While Stroustrup
was working on his Ph.D. thesis in the Computing Laboratory of Cambridge
University, he was fascinated by the program organization and concurrency features
of the Simula programming language, which he used to write a simulator. However,
he discovered that the implementation did not scale well, so eventually the simulator
was rewritten in BCPL. For his work at AT&T Bell Labs, Stroustrup decided to
enhance the C programming language with language features he found so useful in
Simula. He started writing a pre-processor “Cpre” that converted C programs with
Simula-like classes into regular C code that could be compiled with existing
compilers. The new language was initially called "C with Classes." From the start, the
objective was that the new language could be used for everything that C could be used
for so that it was a general-purpose programming language. Also, because C
compilers already were available for many platforms, it inherited C's portability,
which to this day is one of its important quality attributes. Another objective of the
language was to provide better alternatives for unsafe features of C while maintaining
its efficiency and direct access to underlying hardware features. Because of that, it is
also popular in safety-critical application areas such as those in the automotive
industry, where MISRA is one of the most popular coding standards.
6
1.3.2 C with Classes provided:
Classes
Derived classes
Public/private access control
Constructors and destructors
Call and return functions (soon removed due to lack of popularity)
Friend classes
Type checking of function arguments
Inline functions
Default arguments
Overloading of the assignment operator. And much more.
At this point in C++ history, the language didn’t have a proper name. For some time,
it was called C84, but that was kind of confusing. Eventually, it was computer
scientist Rick Mascitti who suggested the name C++, which helped many aware of the
fact that it was a successor of C.
7
LANGUAGE DESIGN PRINCIPLES AND PARADIGMS
2.1 DESIGN PRINCIPLES
Earlier on, I stated that C followed a structure, which was that of ALGOL.
But what do we mean by structure?
Is it its look, behavior, or maybe programming syntax?
1.2.1 Programming Language Design
When we say Design, in the context of programming language, it encompasses how a
solution should look, behave, and be implemented to address a specific problem.
Programming language design involves defining the syntax, semantics, and other
features of a language, providing the rules and conventions necessary for software
development.(Saeed Mohajeryami, PhD. (2022, Dec 27).)
Several factors need to be considered when choosing a language's design, including
its intended use, target audience, and design goals and constraints. These factors guide
the development and documentation of the language, ensuring it meets the needs of its
users while aligning with its intended purpose.
1.2.2 Factors to be Considered When Designing A Programming Language.
The design of a programming language encompasses its syntax, semantics, and
features, all of which play a crucial role in expressing complex ideas and algorithms
while ensuring ease of learning and usage. Syntax dictates the rules for naming
variables and functions, punctuation usage, and code organization, while semantics
8
govern the logic of the code and its interpretation by the computer, including
evaluation of expressions and control structures.
Abstraction in programming languages allows developers to work at different levels
of detail, with mechanisms like data abstraction hiding implementation details and
control abstraction representing complex operations as single units. Data types define
the types of data usable in programs, determining their size, representation, and
allowable operations.
Memory management is essential, handling the allocation and reallocation of memory
resources, including dynamic memory allocation and garbage collection. Concurrency
and parallelism features enable programs to execute multiple tasks simultaneously,
utilizing threads, processes, and asynchronous programming constructs.
Effective error handling mechanisms detect, report, and handle errors and exceptions
during program execution, enhancing program efficiency and correctness.
Extensibility allows a language to be extended with new features or libraries through
modular programming and frameworks. Portability ensures a language can run on
different hardware platforms and operating systems with minimal modifications.
Finally, performance considerations influence the speed and efficiency of program
execution. By considering these aspects, a programming language can strike a balance
between expressiveness, usability, and efficiency, meeting the diverse needs of
developers and users alike.
9
2.2 Programming Paradigms
Before Delving into the The intended uses of C and C++ their objectives and
constraints, let’s talk about their Programming Paradigms and what paradigms mean.
2.2.1 What are Programming Paradigms
According to (Germán Cocca. (2022, May 2)cited in Programming Paradigms-
Paradigm Examples for Beginners), Programming paradigms are different ways or
styles in which a given program or programming language can be organized. Each
paradigm consists of certain structures, features, and opinions about how common
programming problems should be tackled.
Ever wondered why there seem to be a huge influx of Programming Languages in the
world? Well this is because their many Programming Paradigms that exist alongside
them, these paradigms have different structures, a way of solving problems and also
communicating with the machine, I daresay, choosing an array of languages in a
chosen field revolving around programming, is dependent on the kind of solutions
you want to create.
Note, Programming paradigms are not languages or tools that can be used to program,
no. They're like a set of ideals and guidelines that many people have agreed on,
followed, and explored .
And Programming languages aren't always tied to a specific paradigm. There are
languages that have been built with a certain paradigm in mind and have features that
facilitate that kind of programming more than others (Haskel and functional
programming is a good example).
But there are also "multi-paradigm" languages, meaning you can adapt your code to
fit a certain paradigm or another (JavaScript and Python are good examples).
10
Like earlier mentioned the list of Programming Paradigms are exhaustive, but having
C and C++ as our case study, we would only talk about the paradigms that are used in
them.
1. Imperative Programming:
Imperative programming consists of sets of detailed instructions that are given to the
computer to execute in a given order. It's called "imperative" because in a very
specific way.Imperative programming focuses on describing how a program operates,
step by step.Imperative programming, where programs consist of a sequence of
statements that change the program's state, is the foundation of both C and C++.
Imperative programming focuses on describing how a program operates.
2. Procedural Programming:
Procedural programming is a derivation of imperative programming, adding to it the
feature of functions (also known as "procedures" or "subroutines"). Both C and C++
support procedural programming, where programs are structured as sequences of
instructions that operate on data given externally or internally. In procedural
programming, the focus is on algorithms and functions that manipulate data.
3. Object-Oriented Programming
One of the most popular programming paradigms is object-oriented programming
(OOP). The core concept of OOP is to separate different use cases of a particular
behaviour into entities which are coded as objects. Each entity will group a given set
of information (properties) and actions (methods) that can be performed by the entity.
OOP makes heavy usage of classes (which are a way of creating new objects starting
out from a blueprint or boilerplate that the programmer sets). Objects that are created
from a class are called instances. C++ is a multi-paradigm language that fully
11
supports object-oriented programming, while C can emulate some OOP concepts with
struct and function pointers. In OOP, programs are structured as collections of objects
that interact with each other. Key OOP concepts include abstraction, encapsulation,
inheritance, and polymorphism.
2.3 Uses and Limitations of C
So what is the intended use of C? and what were it’s constraints which prompted
developers to sort out newer language such as C++.
They’ll be no comparative analysis of C and C++ if there’s no actual analysis on their
uses and the Constraints around them that lead to developers seeking better options.
To analyse what C++ came to solve that at the time of it’s creation C could not solve.
2.3.1 Features and Benefits
Looking at our introduction to C++ and it’s history, it was clear that Despite Simula
not being as capable as C, C definitely had it’s Limitations, which led to the extension
of C by adding certain Simula like features thereby birthing C++.
Though C is still very much in use today in many industries and not just limited to
technology and computer science, so first of, let’s look at what makes C a force to be
reckoned with.
C is a powerful programming language that offers several benefits over other
languages.
C is a universal language that can be used for various applications.
C is a very efficient language that can write code that is both fast and reliable.
C is a portable language, meaning that code written in C can be easily compiled
and run on various platforms.
12
C is a well-established language with a large and active community of developers
constantly working on improving and creating new tools and libraries.
C program syntax is easy to learn and read; this makes debugging code more
accessible and faster.
C programs are relatively short compared to other languages, which reduces the
time needed to complete them.
C is a powerful programming language that enables developers to create
sophisticated software systems.
C has been around for many years (it was first released in 1979), so many
libraries and tools are available that facilitate its use.
C is used to create Software and Applications such as Operating Systems, for
Creating Other Languages, for performing high computational Tasks like making
3D videos or applications for them, in Embedded Systems.
Limitations of C
C compilers only identify errors and are incapable of handling exceptions.
It doesn’t provide protection. It also doesn’t feature re-usability of source code
extensively.
The process of debugging is difficult. And doesn’t provide strict data type
checking. (i.e. integer data type can be passed for floating datatype)
It uses ASCII character set which is only able to support 256 characters because it
uses 1-byte to represent a character.
It is unable to support some languages like Chinese, Japanese that have more than
256 characters.
C doesn’t provide the OOPs concept.
13
It doesn’t provide binding or wrapping up of data as a single unit.
C doesn’t provide constructor and Destructor.
There are no concepts of Namespaces in C.
2.3.2 Features of C++ not Readily Available in C.
C++ has many features that are not directly available in C, allowing developers to
write more expressive, efficient, and maintainable code. Here are some things you can
do with C++ that are either difficult or impossible to do with C:
1. Object-Oriented Programming (OOP): C++ fully supports OOP concepts such
as classes, objects, inheritance, polymorphism, and encapsulation. These features
allow for better code organization, abstraction, and reusability, making it easier to
manage large-scale software projects.
2. Template Meta-programming: C++ templates enable template meta
programming, a technique for performing computations at compile-time.
3. Standard Template Library (STL): C++ includes the STL, a powerful library of
generic algorithms and data structures such as vectors, lists, maps, and algorithms like
sorting and searching. The STL provides high-level abstractions and reusable
components, reducing the need for manual implementation of common tasks.
4. Exception Handling: C++ supports exception handling, allowing developers to
write robust and reliable code that can gracefully handle errors and exceptional
14
conditions. Exceptions provide a structured mechanism for propagating and handling
errors, improving code maintainability and reliability.
5. Function and Operator Overloading: C++ allows for function and operator
overloading, enabling developers to define multiple functions or operators with the
same name but different parameter types or signatures.
6. Namespace Support: C++ provides support for namespaces, allowing developers
to organize code into logical groups and avoid naming conflicts. Namespaces help
improve code modularity, readability, and maintainability by providing a hierarchical
naming structure.
7. Inline Functions: C++ supports inline functions, which are expanded inline at the
point of invocation rather than being called through a function call mechanism. Inline
functions can improve performance by reducing function call overhead and enabling
compiler optimizations.
Overall, C++ offers a rich set of features and libraries that enable developers to write
more efficient, maintainable, and scalable code compared to C. While C remains a
powerful language for systems programming and low-level development, C++
extends its capabilities to support a broader range of application domains and
programming paradigms.
Though simply put even witheir differences in syntax, libraries and more, there is
notthing C can do that C++ cannot do.
15
REFERENCE
Atul Harsha. (2023, Dec 22). Difference between C and C++.
https://www.shiksha.com/online-courses/articles/difference-between-c-and-cpp-
programming-languages/#:~:text=Key%20Difference%20Between%20C%20and
%20C%2B%2B%20Language,C%20does%20not%20support%20inheritance.
Frank van den Beuken. (2023, Nov 29). A Brief History of C++.
https://www.perforce.com/blog/qac/misra-cpp-history#:~:text=C%2B%2B%20was
%20invented%20by%20Danish,was%20working%20on%20his%20Ph.
Upgrad.com. History of C Programming Language.
https://www.upgrad.com/tutorials/software-engineering/c-tutorial/history-of-c-
language/
Jasdeep Bhatia. Difference between C and C++.
https://pwskills.com/blog/difference-between-c-and-c/
Sanjay K M. ( 2023, March 28). The Evolution of Programming Languages: Past,
Present, and Future. https://www.linkedin.com/pulse/evolution-programming-
languages-past-present-future-mohindroo-/
Saeed Mohajeryami, PhD. (2022, Dec 27). Programming language design.
https://bootcamp.uxdesign.cc/programming-language-design-
a649513dbcf7#:~:text=Programming%20language%20design%20is%20the,software
%20in%20a%20specific%20language.
Germán Cocca. (2022, May 2). Programming Paradigms – Paradigm Examples for
Beginners.
16
https://www.freecodecamp.org/news/an-introduction-to-programming-paradigms/
Freshers Now .(Not Applicable). Features and Limitations of C.
.https://tutorials.freshersnow.com/cprogramming/c-features-limitations/
#:~:text=Limitations%20of%20C%20Language,usability%20of%20source%20code
%20extensively.&text=It%20uses%20ASCII%20character%20set,byte%20to
%20represent%20a%20character.
Ravikiran A S. (2023, May 17). Use of C Language: Everything You Need to Know
https://www.simplilearn.com/tutorials/c-tutorial/use-of-c-language#:~:text=The%20C
%20programming%20language%20was%20created%20with%20the%20intention
%20of,development%20of%20multiple%20operating%20systems.
Nikita Duggal. (2023, Jul 24). Top 12 Uses of C++
https://www.simplilearn.com/tutorials/cpp-tutorial/top-uses-of-c-plus-plus-
programming
Daragh Ó Tuama.(2023). What Is A Programming Language.
https://codeinstitute.net/global/blog/what-is-a-programming-language/
17