Introduction To C++



In 1998, Bjarne Stroustrup developed C++, an extension of the C programming language. Both the programming languages, C and C++ share the basic syntax and code structure. C++ is an object-oriented programming language that can be used on a variety of platforms, including Microsoft, Oracle, IBM, and Intel, to name a few. C++ can be used for programming low level applications like drivers and kernels as well as higher- level applications like games and desktop apps as it is a middle-level language.


C++ is a simple programming language that comes with a large library. It is compiled, which contributes to its pace. Object-Oriented support in C++ aids in the creation of maintainable and extensible programmes. Large-scale applications, in other words, are possible to develop. However, C++ has the relevant features which makes it important even in the current period.


Users can control storage addresses directly with pointer support in C++. Low-level programming is aided by this. Chrome and Microsoft are two browsers that use it. Evernote, LinkedIn, Microsoft, Opera, NASA, and Facebook are only a few of the well-known software companies that use C++. C++ has long been used by Wall Street and the financial industry for high-volume, high-frequency trading since it is easy to use for modelling and data simulations.



Data Types in C++


During the declaration of all variables, data-type is used to limit the type of data that can be stored. As a result, data types are used to tell variables what kind of data they can hold. When a variable is declared in C++, the compiler allocates memory for it depending on the data-type it is declared with. Every type of data necessitates a different amount of memory.


There are primarily three data types in C++


1. Primitive Data Types

These data types are predefined or built-in data types that the user can use to declare variables directly. Integer, character, double floating point, and other primitive data types are available in C++.


2. Derived Data Types

The data types generated by combining primitive or built-in datatypes are known as derived data types. The four types of derived data types are Functions, Arrays, Pointers, and References.


3. User-Defined Data Types

The user determines which data types to use. Define a structure or a class in C++. These user-defined data types are available in C++: Typedef, Class, Structure, Union, Enumeration.


Operators In C++

Operators in programming languages are basically symbols that instruct the compiler to perform specific mathematical or logical functions. The following are the built-in operators in C++:


  • Arithmetic Operators

  • Relational Operators

  • Logical Operators

  • Bitwise Operators

  • Assignment Operators

  • Misc Operators


Learn the values of these operators and how to use them in C++ in the video below.



Conditional Statements


C++ has the following conditional statements:


If - If a given condition is valid, a block of code is specified to be executed.

Else - If the same condition is incorrect, you can assign a block of code to run using this statement.

Else If - If the first condition is incorrect, you may choose a new condition to evaluate.

Switch- Defines a large number of different code blocks to be run

Nested If - To define an if statement inside another if statement, use the nested If Conditional statement.

Ladder - This statement will skip the rest of the lines if the linked condition statement is true.

Want to learn more about these conditional statements? Watch the video below:



Loops In C++


When we need to execute a block of statements repeatedly, we use programming loops. In computer programming, a loop is a sequence of instructions that is repeated until a specific condition is met. The three key statements that make up a loop are the initialization expression, test expression, and update expression. However, the two main types of loops in C++ are:


1. Entry Controlled loops: This type of loop evaluates the test condition before entering the loop body. Entry regulated loops include For Loop and While Loop.


For Loop - A for loop is a repetition control mechanism that allows you to make a loop that repeats a certain amount of times. The loop allows one to perform an infinite number of steps in a single line. A loop variable is used to monitor the loop in for loop.


While Loop - When the exact number of loop iterations is unknown, while loops are employed. The loop execution is halted based on the test condition.


2. Exit Controlled Loops: In this type of loop, the test condition is measured at the end of the loop body. As a result, the loop body will execute at least once regardless of whether the test condition is true or false.The exit managed loop is the do – while loop.


Do- While Loop - The loop execution is also terminated based on the test condition in do while loops. The do while loop differs from the while loop in that the state is measured at the end of the loop body, whereas the other two loops are entry regulated loops.


Nested Loop - Any other ‘while', ‘for', or ‘do..while' loop may have one or more loops within it. Nesting is supported by C++ to a maximum of 256 levels.


Loop Control Statements


The execution of a loop is changed by using loop control statements. When execution exits that scope, all automated objects created in that scope are deleted.


1. Break Statement: The break statement stops the loop or move statement and passes control to the next statement in the chain.


2. Continue Statement: This directs the loop to skip the rest of its body and retest its condition before repeating the process.


3. Goto Statement: The control is passed to the labelled statement. However, using goto statements in your programme is not recommended.


Functions In C++


A function is a collection of statements that take inputs, perform a particular calculation, and return results, thus reducing code redundancy. The number of parameters a function requires, the data types of the parameters, and the function's return type are all specified in a function declaration.

In C++, there are two types of functions


Built-in Functions

Library functions are another name for built-in functions. These functions are provided by C++ and the programmers are not required to write it. These functions can be used directly in code.


User-Defined Functions

As the name suggests, user-defined functions are defined by the user. The functions can be described anywhere in the programme and then called from anywhere in the code.


Learn how to implement the functions along with advance features in the video below




Parameters In Functions


Real parameters are those that are transferred to a function, while formal parameters are those that are obtained by the function. Passing parameters can be done in one of two ways.


Pass by Value: This parameter passing procedure copies the values of actual parameters to the function's formal parameters, and the two types of parameters are stored in different memory locations. As a result, any changes done within functions do not appear in the caller's parameters.


Pass by Reference: Since the caller's actual and formal parameters apply to the same locations, any adjustments made within the function are reflected in the caller's actual parameters by this.


There is more to C++ like Strings and Arrays. Learn all this and much more with Newton School Launchpad for FREE. The C++ is well accustomed for beginners and consists of 10+ lectures, and 10 assignments. Register yourself now!

https://www.newtonschool.co/launchpad