0 - C++ - Overview

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

0 - C++_Overview

0.1 - what is C and C++?


C and C++ are both programming languages commonly used for system programming, application development, and other software
development tasks. Here's a brief overview of each:
C Programming Language:
 C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in the early 1970s.

 It was designed to be a simple, efficient, and portable language for developing system software, such as operating systems and compilers.

 C is known for its close-to-the-hardware nature, making it suitable for tasks that require direct access to system resources and low-level
memory manipulation.

 It provides constructs for low-level programming, such as pointers and manual memory management, giving programmers fine-grained
control over system resources.

 C has influenced many other programming languages and is often used as the foundation for developing software in various domains.
C++ Programming Language:
 C++ is an extension of the C programming language with added features for object-oriented programming (OOP).

 It was developed by Bjarne Stroustrup at Bell Labs in the 1980s as an enhancement to C, adding support for classes, inheritance,
polymorphism, and other OOP concepts.

 C++ retains compatibility with C, allowing C++ programs to incorporate C code and vice versa.

 In addition to OOP, C++ also supports generic programming through templates, which allow the creation of reusable, type-safe functions
and data structures.

1
0 - C++_Overview

 C++ is widely used in various domains, including game development, system programming, embedded systems, and large-scale software
projects.
0.2 - why we need c++
1. Object-Oriented Programming (OOP) Features:
C++ supports OOP concepts such as classes, objects, inheritance, polymorphism, and encapsulation. This allows for the creation of
modular, reusable code that is easier to understand, maintain, and extend. OOP promotes code organization and abstraction, leading to more
scalable and maintainable software.
2. Performance:
C++ offers high performance and efficiency, making it suitable for resource-intensive applications such as games, simulations, real-time
systems, and embedded systems. C++ allows fine-grained control over memory allocation and management, enabling developers to optimize
code for speed and memory usage.
3. Compatibility with C:
C++ is compatible with C, meaning C++ code can incorporate C libraries and vice versa. This interoperability allows developers to
leverage existing C codebases and libraries while taking advantage of C++'s additional features. It also facilitates the gradual transition of legacy
C code to C++.
4. Standard Template Library (STL):
C++ includes the Standard Template Library (STL), which provides a rich collection of generic data structures (such as vectors, lists,
maps, and queues) and algorithms (such as sorting, searching, and manipulation). The STL allows developers to write efficient, type-safe code
without reinventing the wheel, saving time and effort.
5. Flexibility:
C++ is a versatile language that can be used for a wide range of applications, including desktop software, mobile apps, web development
(via frameworks like Qt), game development (using engines like Unreal Engine), system programming, scientific computing, and more. Its
flexibility and scalability make it suitable for both small-scale projects and large-scale enterprise applications.

2
0 - C++_Overview

6. Community and Ecosystem:


C++ has a large and active community of developers, educators, and contributors who continually improve the language, develop
libraries and frameworks, share knowledge, and provide support. This vibrant ecosystem ensures that developers have access to resources, tools,
and expertise to tackle a variety of challenges.
0.3 – Compiler vs Interpreter
A compiler and an interpreter are both tools used in the process of translating source code into machine code or executing it, but they operate in
different ways:
1.Compiler:
 A compiler is a program that translates the entire source code of a program into machine code or an intermediate representation known as
object code.

 The compilation process typically involves multiple stages, including lexical analysis, syntax analysis, semantic analysis, optimization,
and code generation.

 Once the compilation process is complete, the resulting executable file contains machine code that can be directly executed by the
computer's hardware.

 Examples of compiled languages include C, C++, Java (to bytecode), and Rust.
2.Interpreter:
 An interpreter is a program that reads and executes source code line by line, translating each line into machine code or executing it
directly.
 Instead of translating the entire program upfront, an interpreter processes code on-the-fly, executing each statement sequentially.

 Interpreters are often used in scripting languages and languages with dynamic typing, where runtime flexibility is valued over
performance.

3
0 - C++_Overview

 While interpreters may provide greater flexibility and interactivity during development, they can be slower than compiled languages
since they don't produce optimized machine code.

 Examples of interpreted languages include Python, JavaScript, Ruby, and PHP.


Comparison:
Speed: Compiled languages generally tend to execute faster than interpreted languages because the compilation process optimizes the code for
the target platform. Interpreted languages, on the other hand, have the overhead of parsing and executing code at runtime.
Portability: Interpreted languages are often more portable since the interpreter itself can be ported to different platforms, allowing the same
source code to run on various systems without modification. Compiled languages may require recompilation for different platforms.
Debugging: Debugging can be more straightforward in interpreted languages since errors are often reported in terms of the source code. In
compiled languages, debugging can be more challenging because optimizations may change the relationship between source code and generated
machine code.
In practice, many modern languages and environments use a combination of compilation and interpretation techniques, such as Just-In-Time
(JIT) compilation, which compiles code at runtime for improved performance.

4
0 - C++_Overview

5
0 - C++_Overview

C C++

C was developed by Dennis Ritchie between the year 1969 and


C++ was developed by Bjarne Stroustrup in 1979.
1973 at AT&T Bell Labs.

C does no support polymorphism, encapsulation, and inheritance C++ supports polymorphism, encapsulation, and inheritance because
which means that C does not support object oriented programming. it is an object oriented programming language.

C is (mostly) a subset of C++. C++ is (mostly) a superset of C.

Number of keywords in C: Number of keywords in C++:


* C90: 32 * C++98: 63
* C99: 37 * C++11: 73
* C11: 44 * C++17: 73
* C23: 59 * C++20: 81

C++ is known as hybrid language because C++ supports


For the development of code, C supports procedural programming.
both procedural and object oriented programming paradigms.

Data and functions are separated in C because it is a procedural Data and functions are encapsulated together in form of an object in
programming language. C++.

6
0 - C++_Overview

C C++

Data is hidden by the Encapsulation to ensure that data structures and


C does not support information hiding.
operators are used as intended.

Built-in data types is supported in C. Built-in & user-defined data types is supported in C++.

C is a function driven language because C is a procedural C++ is an object driven language because it is an object oriented
programming language. programming.

Function and operator overloading is not supported in C. Function and operator overloading is supported by C++.

C is a function-driven language. C++ is an object-driven language

Functions in C are not defined inside structures. Functions can be used inside a structure in C++.

Namespace features are not present inside the C. Namespace is used by C++, which avoid name collisions.

Standard IO header is stdio.h. Standard IO header is iostream.h.

7
0 - C++_Overview

C C++

Reference variables are not supported by C. Reference variables are supported by C++.

Virtual and friend functions are not supported by C. Virtual and friend functions are supported by C++.

C does not support inheritance. C++ supports inheritance.

Instead of focusing on data, C focuses on method or process. C++ focuses on data instead of focusing on method or procedure.

C provides malloc() and calloc() functions for dynamic memory C++ provides new operator for memory allocation and delete
allocation, and free() for memory de-allocation. operator for memory de-allocation.

Direct support for exception handling is not supported by C. Exception handling is supported by C++.

scanf() and printf() functions are used for input/output in C. cin and cout are used for input/output in C++.

C structures don’t have access modifiers. C ++ structures have access modifiers.

C follows the top-down approach C++ follows the Bottom-up approach

8
0 - C++_Overview

C C++

Strict type checking in done in C++. So many programs that run well
There is no strict type checking in C programming language. in C compiler will result in many warnings and errors under C++
compiler.

C does not support overloading C++ does support overloading

Type punning with unions is undefined behavior (except in very


Type punning with unions is allows (C99 and later)
specific circumstances)

Named initializers may appear out of order Named initializers must match the data layout of the struct

File extension is “.c” File extension is “.cpp” or “.c++” or “.cc” or “.cxx”

Meta-programming: templates (macros are still supported but


Meta-programming: macros + _Generic()
discouraged)

There are 32 keywords in the C There are 97 keywords in the C++

9
0 - C++_Overview

C C++

10

You might also like