What is C++? A Beginner’s Guide
C++ is a general-purpose programming language with object-oriented programming (OOP) principles, memory management, and an extensive library of classes. C++ is considered a type-safe language due to the OOP principles allowing developers to hide and protect variables. It is also a high-performance language.
History of C++
C++ is a programming language based on the C language developed by Dennis Ritchie in the early 1970s at Bell Labs. C++ was developed by Bjarne Stroustrup at Bell Labs in the early 1980s. C++ was designed to be C with classes. Today, the modern C++ Standard Library has a rich collection of classes and functions.
Last Updated October 2020
Classroom and Hands-on sessions- Features of C++ 11 , Exception Handling and STL – for Both Academics and Industry | By Abdul Bari
Explore CourseC++ is standardized by the International Organization for Standards (ISO). Since 2012, the language has been on a three-year publication schedule. The next two planned releases are C++20 and C++23.
C++ Usage
C++ can be used with different programming styles, including procedural, object-oriented, and functional. The C++ Standard Library has an extensive set of classes and functions related to graphical user interface (GUI) development. The library support tools, language flexibility, and performance characteristics lend the language to a wide range of applications, including games, server components for cloud and distributed systems, GUI applications, banking software, browsers, and operating systems.
.Net, Java and most JavaScript interpreters are also written in C and C++.
Companies that use C++
Many companies use C++ for mission-critical applications and components.
For example:
- Airline Flight Control Systems
- Facebook uses C++ for back-end server components.
- Blizzard Entertainment uses C++ for heavy graphics on its hardware.
- Bloomberg uses C++ for financial trading software.
- Adobe developed Photoshop Illustrator in C++.
- Microsoft Windows OS
- Mozilla Firefox and Thunderbird
Features of C++
Some of the most important features of C++ are related to data security, data encapsulation, and data hiding. Defining objects with data and functional classes provides a type-safe environment.
C++ also offers the following features:
- Platform independence
- Portability
- Pointers
- Classes and objects
- Dynamic memory allocation
- Inheritance
- Data abstraction
- C++ Standard Library classes and functions
- Memory management
- Operator overloading
Some of these features are advanced and provide developers with a deep level of control and access to the OS and hardware.
Differences between C and C++
Feature | C | C++ |
---|---|---|
Programming Approach | Procedural Programming | Allows for procedural, object-oriented, and functional approaches |
OOP | Not Supported | Fully supports OOP |
Data Types | Contains Structures for user-defined datatypes. | In addition to user-defined data types, the C++ Standard Library has standardized data types. |
Data Security | C does not support encapsulation so data behave as a free entity and can be manipulated by outside code. | C++ encapsulation hides the data to ensure that data structures and operators are used as intended by object classes and functions. |
Interoperability | Cannot run C++ programs. | Can include and execute most C programs. |
Keywords | 32 keywords. | 60 keywords. |
Exception and Error Handling | Exception handling is not supported. | Exception handling is supported. |
Program Structure | Focuses on procedures and methods | Focuses on objects with functions, classes, and data |
Optimization and Performance | Optimizes code using macro functions. | Uses inline functions to optimize code. |
C++ Program Structure
// Basic Hello World
#include <iostream>
int main()
{
std::cout << "Hello World!";
}
This is a basic Hello World program. Let’s look at each line to understand the program.
Comment – // Basic Hello World
Text that is prefaced with two slashes is ignored by the compiler and allows the developer to add notes to indicate the intent of the code
Preprocessor Directive – #include <iostream>
Lines beginning with a hash sign (#) are directives. In this case, the directive is to include the iostream C++ Standard Library functions.
Main Function – int main()
A function includes three components. The type of function – in this case, int for integer. The name of the function – main. Main is a special function name because it is the function the program will run when it is started. The last component is a set of optional parameters.
Note that there are open and closing brackets {}. These define the start and end of the function and all lines of code within these brackets are executed with that function.
Function Statement – std::cout << “Hello World!”;
This is the line of code executed by the main function. It uses “std::cout” which is part of the iostream library included at the beginning. ‘std::cout’ is the standard character output device, and this is usually the computer screen. The insertion operator (<<) indicates we want to insert something into the standard character output device. The text in quotes – “Hello World!” – is what will be inserted.
This function statement prints “Hello World” to the computer screen.
Notice the line ends with a semicolon (;). The semicolon marks the end of a statement.
This same program could be written with a function to write the text to the screen. In this case, the main function calls the print_hello function to output the text to the screen.
// Basic Hello World with functions
#include <iostream>
int main()
{
print_hello();
}
int print_hello()
{
std::cout << "Hello World!";
}
Conclusion
C++ is a vast but easy to understand programming language, with a wide range of different implementations. And the best way to learn C++ is by taking a course like this one on Udemy.
Top courses in C++
C++ students also learn
Empower your team. Lead the industry.
Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.