C++ File Format | .cpp Extension
C++ is a general-purpose programming language that extends C with features such as classes and objects, allowing for object-oriented programming. A C++ programming language file has a .cpp file extension. It allows developers to write clean and efficient code for large applications and software development, game development, and operating system programming.
Table of Content
- History of C++
- Features of C++
- Syntax of C++
- Advantages of C++
- Disadvantages of C++
- Conclusion
History of C++
C++ was developed by Danish computer scientist Bjarne Stroustrup in the early 1980s. Stroustrup began working on what would become C++ in 1979 at Bell Labs. Stroustrup’s work resulted in the creation of a new language called “C with Classes” in 1983. C++ was further defined with the release of C++03, C++11, C++14, C++17, and C++20. Each new version added new features, improvements, and enhancements to the language, addressing issues and adapting to shifting programming paradigms. C++ became popular because of its flexibility, efficiency, and broad applicability. It has been widely used in systems programming, game development, embedded systems, high-performance computing, and more.
Features of C++
It is an imperative and compiled language. C++ has several features, including:
- Object-Oriented Programming
- Machine Independent
- Simple
- High-Level Language
- Popular
- Case-sensitive
- Compiler Based
- Dynamic Memory Allocation
- Memory Management
- Multi-threading
Syntax of C++
C++
#include <iostream> using namespace std; int main() { cout << "GFG!" ; return 0; } |
Code Explanation:
- The header files are defined at the top of the program and contain the definitions of the functions and macros we are using in our program.
- The namespace used in C++ provides a scope or a region where we define identifiers. It is used to avoid name conflicts between two identifiers as unique names can be used as identifiers.
- Functions are basic building blocks of a C++ program that contain the instructions for performing some specific task. Apart from the instructions present in its body, a function definition also contains information about its return type and parameters.
Advantages of C++
- C++ is an object-oriented programming language. It consists of a series of commands that instruct the computer to perform a specific task.
- It’s a problem-oriented language, far more user-friendly than other low-level languages such as binary coding.
- It has a vast and mature standard library that provides a wide range of functionality, including I/O operations, mathematical functions, and data structures.
Disadvantages of C++
- The C++ program is complex during a very large high-level program, and C++ is employed for platform-specific applications commonly, For the actual OS or platform, the library set is typically chosen.
- It program can’t support garbage pickup, It’s not secure because it’s a pointer, friend function, and global variable and it has no support for threads built-in.
- It is a complex and powerful language that can take time to learn and master, especially for beginners who are new to programming.
Example Code: Simple program to add two number
C++
#include <iostream> int main() { // Declare variables to store user input double num1, num2; // Prompt the user to enter the first number std::cout << "Enter the first number: " ; std::cin >> num1; // Prompt the user to enter the second number std::cout << "Enter the second number: " ; std::cin >> num2; // Calculate the sum of the two numbers double sum = num1 + num2; // Display the result std::cout << "The sum of " << num1 << " and " << num2 << " is: " << sum << std::endl; // Return 0 to indicate successful program execution return 0; } |
Output:
Enter the first number: 10
Enter the second number: 20
The sum of 10 and 20 is: 30
Conclusion
At last, C++ is one of the favorite languages used by developers when it is time to work in the field of game applications, operating system development, and many more things. C++ GUI support gives leverage to the developer to build complex applications. The .cpp file extension can be only used for C++ program files.
Contact Us