Sign in
Log inSign up

Why C? Why C++?

C++ is the modern world!!

Ananya Vishnoi
·May 29, 2021·

5 min read

Why C? Why C++?

C programming is not difficult to learn. However, the initial slope is always boring and difficult to claim. For that, I create this guide to get you up and run.

C and C++ are no longer the 'same' language. Referring to them as C/C++ is out of date. The immediate successor to C is C++. An underlying rule for both languages is you don't pay for what you don't use. That reduces the code image size. Another rule is speed. If you don't like the complexity of a language, any language, then you won't appreciate the complexity of the problems that need to be solved. You need to check back on TIOBE. For November '20 C is first followed by Java, Python, and C++.

Perspectives and Approach

C++ is Big

C++ is a big language. Or so many say. What exactly do they mean by big? I don’t really know. The list of reserved words isn’t much different from other languages. If you ignore the eleven provided to allow usage by non-ASCII languages there are thirty-two inherited from C and thirty added by C++. That’s sixty-two reserved words. Java has fifty. C# has eighty. Is it library size? Ever try to understand the Java libraries? The actual libraries for the two languages may be similar in sizes but C++ provides working defaults that simplify the use of the library. …

Advantages of C++

C++ is a powerful, efficient, and fast language. Object-oriented programming language- four principles of object-oriented programming are encapsulation, abstraction, inheritance, and polymorphism. Overall this helps avoids code duplication and increases code reusability. Encapsulation makes data abstraction (security or privacy to data) possible and is achieved with the help of a class. Inheritance is used to provide the concept of code-reusability. Polymorphism makes a language able to perform different tasks at different instances. Abstraction represents the needed information in a program without presenting the details. Wide range of applications — from Machine Learning to building games in Unity and Unreal to real-time mathematical simulations to programming smart contracts. If you didn’t know Tensorflow, one of the most widely used Machine Learning libraries in the world uses C++ as the backend programming language. Memory Management — C++ gives the user complete control over which is an advantage and a disadvantage as this increases the responsibility of the user to manage memory rather than it being managed by the Garbage collector. Library Support — standard libraries for various containers like sets, maps, hash tables, etc. Creator In 1983, Bjarne Stroustrup released C++.He was an employee of Bell AT &T and started working on language “C with classes”. Now it’s more than just classes.

C++ It is a high-level language designed to be readable for you and other developers. The ++ comes from the C increment operator ++. No, you don’t need to learn C to use C++.

The semantics of the cpp** At the very basic level, a C++ project will contain just one file: the C++ source file, typically with the extension CPP which stands for c plus plus.

The semantics of the C** At the very basic level, a C project will contain different files: the C source file, typically with the extension C.

Starting with the Main One of these pieces is the main() function is the part that runs first. For now, all you need to know is that every C++ application has a main() function.

#include // The entry point of the program int main() { std::cout << “Hello, world!”; return 0; }

Breaking down the Syntax

The first line starting with #include. Various types of messages you can send (a few are #define, #ifdef, #pragma ) #include tells the compiler to copy the contents of the specified file into the source file at this point.

#include int main() { std::cout << “Hello, world!”; return 0; }

angle brackets (<>) indicate that the compiler should look in the standard directories used to store header files, but you can provide the absolute location of a header file (or the location relative to the current file) using double quotes (″″ Comments — the line starting with //. Another comment could be started with / and ends with / and everything between these two symbols is a comment, including line breaks.

Braces — code blocks {}, wherein this case used for the function main Parentheses are empty(), currently, this function has no parameters. But normally this is used to declare the parameters passed to the function and to their types. your function int main(), which is the starting point of your c++ application has to return int (i.e an integer).

The main function has just one line of code; this is a single statement starting with std and ending with the semicolon (;) single statement prints the string Hello, world! the string is enclosed in double quote marks (″″) the string is put to the stream object std::cout using the operator << The C++ Standard Library defines other <<operators that allow other data types to be printed to the console.

Using the Namespace std instead In this case, std stands for the standard namespace. That includes cout, cin, string, vector, map, etc. So it is popular to add “using namespace std” at the top of the source code so that you won’t have to type the std:: prefix again. Namespaces are names given to parts of code that help in reducing the potential for a naming conflict.

**Before using Namespace

#include int main() { std::cout << “Hello, world!”; }

After using Namespace including Breakdown of the Syntax

//Preprocessor directive

#include // Entry point of the program int main() { /Tell the compiler what namespace to search with namespace std;/ using namespace std; / Write to the screen using std::cout/ cout << “Hello, world!”<< endl; //Returns a value return 0; }