Showing posts with label CPP. Show all posts
Showing posts with label CPP. Show all posts

FUNCTIONS IN CPP | LEARNING CPP ONLINE

What is the C++ function?

A function in C++ is a designated section of code that carries out a certain activity. It is a key building component of C++ programming that aids in grouping together unwieldy pieces of code into manageable chunks. A program can be divided into smaller, more manageable components using functions, which makes it simpler to comprehend, test, and maintain.

A function declaration and a function definition make up most functions in C++. The function definition contains the actual code that is performed when the function is called, whereas the function declaration specifies the function's name, return type, and optional parameters.

Here is a straightforward C++ function declaration and definition example:


In this example, the function is named and numbers and it takes two integer parameters a and b. It returns an integer value, which is the sum of the two input parameters. The function definition contains the code that performs the addition and returns the result.

To use this function, you would call it from another part of your program, passing the required arguments, and receive the result:


After executing this statement, the variable result would hold the value 8, which is the sum of 5 and 3.

If a function doesn't need to return a value, it can alternatively be defined without a return type (void). They may have many kinds of parameters or none at all.

With the help of C++ functions, you may reuse code, make it easier to maintain, and break up the logic of your programs into logical chunks for better organization and comprehension.

Why do we use the function?

A crucial component of computer languages like C++ is functions. Use functions in your code for the following reasons:

  • Code reuse is made possible via functions, which let you write a block of code just once and use it repeatedly throughout your program. Instead of repeatedly creating the same code, you can quickly accomplish a certain action by encapsulating it into a function that can be called whenever you need to. This encourages code uniformity, saves time and effort, and lessens the likelihood of introducing errors.
  • Functions aid in the modularization of a program by dividing it into smaller, stand-alone components. The code is more organized and simpler to handle when each function is in charge of a certain task or functionality. Consider functions as modular pieces that can be used to build intricate programs. This modular approach improves the readability, maintainability, and debuggability of the code.
  • Abstraction: By obscuring the specifics of a task's implementation, functions offer a certain level of abstraction. You simply need to be aware of a function's purpose and usage while using it; you don't need to understand how it is internally implemented. This abstraction makes programming easier and frees you up to concentrate on your program's high-level logic rather than becoming mired down in the low-level implementation details.
  • Code Readability: Functions help the code be easier to read and comprehend. You can convey the goal or usefulness of the code contained in a function by giving it a name that makes sense. This makes the code more readable and makes it simpler for you to grasp the code's purpose as well as that of others.
  • Testing and Debugging: Functions facilitate testing and troubleshooting. It is simpler to find and resolve problems since functions isolate particular jobs so that you can test and debug each one separately. This modular strategy aids in problem isolation and lowers troubleshooting complexity.
  • Scalability and Maintainability: Functions help your codebase be scalable and maintainable. Functions enable you to control complexity as your program expands by breaking it down into more manageable parts. Instead of searching and altering the entire codebase, you simply need to edit the relevant function if you need to enhance or extend a certain capability. This lessens the chance of making errors during revisions and enhances the maintainability of the code.
Briefly put, C++ functions provide code reuse, modularity, abstraction, better code readability, simpler testing and debugging, and scalability and maintainability. They are an effective tool for structuring, managing, and organizing your code, which results in more robust and effective programs.

Types of function

In C++, functions can be divided into a number of kinds according to their usage and properties. Here are a few typical kinds of functions:

  • Build-in function: Functions that are built into the C++ programming language are known as built-in functions. Since they are a component of the standard library, you can use them right away in your code without having to implement them further. Printf(), scanf(), sqrt(), and strlen() are a few examples. Common operations and activities are provided by these functions.
  • User-defined Functions: These are functions that the programmer defines to carry out particular activities as required by the program. To modularize code, increase reusability, and simplify code organization, programmers construct user-defined functions. To meet the needs of your program, you can build functions with a variety of return types, input arguments, and functionality.
  • Recursive function: Functions that repeatedly call themselves are referred to as recursive functions. By segmenting a problem into smaller subproblems and resolving each one in turn, they are able to solve it until they reach the base case. For instance, calculating factorials, locating Fibonacci numbers, and navigating tree structures are all examples of issues that can be solved with recursive functions.
  • Inline function: Inline functions are functions that the compiler expands at the point of call rather than being called as a separate function. Because function call overhead is decreased, performance may be enhanced. Before the function definition, the inline keyword can be used to specify an inline function.
  • Function Templates: You can build general functions that can operate on various data types by using function templates. They give you a mechanism to define a single function definition that you can use with a variety of types, allowing you flexibility and code reuse. The template keyword is used to define function templates, and they can include one or more template arguments.
  • Constructor Functions: When an object of a class is formed in C++, a special function known as a constructor is called. They carry out any required setup actions as well as initialize the object's data members. Constructors do not provide a return type and have the same name as the class. They can be overloaded to give the class several initialization options.
  • Destructor function: Destructor functions are unique procedures that are called whenever an object of a class is destroyed or exits its scope. Any resources that the object accumulated throughout its lifetime must be cleaned up by them. There are no parameters or return types in destructors, which have the same name as the class and are followed by a tilde ().

Built-in function

The C++ standard library provides built-in functions, also referred to as library functions. Without the need for additional code, these functions are already implemented and may be used in your C++ programs. Here are a few instances of built-in features:

cout and cin from the <iostream> library are used for console input and output.

1. Functions for input and output

Console input and output are handled by the <iostream> library's functions cout and cin.


2. Functions in mathematics:

The <cmath> library's sqrt() function determines a number's square root.


3. String operations

The <cstring> library's strlen() function returns the length of a string.


4. Characteristic Purposes

The <cctype> library's isalpha() function determines whether a character is an alphabet letter.


These are but a handful of instances of C++'s built-in functions. Mathematical computations, string manipulation, file handling, memory management, and other operations are all available through the C++ standard library. To streamline coding duties and make use of pre-existing functionality, you can incorporate the proper header files and use these functions in your programmers’.

User-define function

A function written by the programmer to carry out a particular duty within the software is known as a user-defined function. You can use it to organise code better, increase reusability, and modularize it. Depending on the needs of the programme, user-written functions might have a variety of return types, parameters, and functionality. They are defined by the programmer. Following are a few illustrations of user-defined functions:

  • Addition function: 

The addNumbers() function is defined in this example to compute the sum of two numbers. It executes the addition operation on two integer arguments, a and b, and then returns the outcome.

  • Factorial function:

To determine the factorial of a number, the factorial() function is defined in this example. A base case is eventually found after using recursion to divide the problem into smaller subproblems.
  • Print message function:

The printMessage() function is defined in this example to print a straightforward message. It serves only to encapsulate the printing mechanism and has no parameters or return value.

These are only a few illustrations of C++ user-defined functions. Depending on the particular needs of your program, user-defined functions can have a variety of structures and functionalities. They let you encapsulate functionality, make your code easier to comprehend, and encourage code reuse.

Recursive function

A function that calls itself within its own body is said to be recursive. Programmers can utilize this potent strategy to solve issues that can be divided into smaller issues. Recursive functions often have a base case that specifies when they should stop calling themselves. They operate by breaking down the original problem into smaller and easier subproblems until the base case is reached. A recursive function is demonstrated here:



The factorial of an integer n is calculated in this example via the recursive function factorial(). When n is equal to 0 or 1, which happens in the base case, the function just returns 1. The function calls itself with the argument n - 1 and multiplies it by n for any other value of n. Recursively, this process goes on until the base case is reached.

By repeatedly calling factorial() with decreasing numbers, the program divides the problem into smaller subproblems when it runs factorial(5): factorial(5) call factorial(4), which calls factorial(3), and so on until it reaches the base case. Once the base case is reached, the recursion begins to unwind, multiplying the results at each stage until the desired outcome is realized.

The output of the program would be:


Recursive functions come in handy when dealing with issues that have recurring patterns and can be broken down into more manageable sub-issues that are all exactly the same. To prevent infinite recursion, the recursive function must have an appropriate base case and termination condition.

Inline function

An "inline function" is a programming concept that allows the compiler to insert the function's code right away at the time the function is invoked rather than producing a separate function call. This can improve performance by removing the overhead of function calls.

The following C++ example will demonstrate how inline functions work:


In this illustration, we defined an inline square function that computes the square of a number. The compiler substitutes the function call with the actual function code when the square function is called in the main function. This indicates that the code that was executed resulted in = x * x;.

When a function is small and the performance impact of function calls would be obvious, it can be advantageous to use inline functions. It's crucial to remember that the compiler ultimately decides whether or not to inline a function, and the inline keyword only serves as a hint to the compiler. The inline keyword need not always be used explicitly because modern compilers may frequently perform optimizations automatically.

Function template

In C++, you can build generic functions that work with many data types without having to write several function definitions. Templates allow for code reuse and flexibility when building algorithms or operations that may be applied to several types.


In this instance, we've defined a maximum function template. The generic type represented by the template parameter T will be chosen when the function is invoked. The greater value is returned by the function after comparing two values of type T.

To determine the maximum of several kinds in the main function, we use the maximum function template. With two integers, two doubles, and two characters, we call maximum. The proper versions of each function are created by the compiler automatically depending on the data type.

When the code is compiled, the compiler generates the following function instantiations:


The code demonstrates how the same function template may be used with several data types, enabling code reuse and obviating the need to write separate versions of the function for each data type.

Keep in mind that function templates can potentially include numerous template arguments, enabling more flexible generic functions.

Constructor function

When an object belonging to a class is formed, a constructor, which is a special member function of the class or struct, is automatically called. The initial state of the object is built up in the constructor, which is also used to initialize the class's data members. In other words, constructors offer a method for creating and initializing class objects.

A C++ example is provided below to demonstrate constructor functions:


In this illustration, the rectangular form is represented by the class named rectangular. There are two constructors for the Rectangle class: a parameterized constructor and a default constructor.

When creating an object without any arguments, Rectangle(), the default constructor, is invoked. In this instance, the rectangle's width and height are both set to 0. When we build the defaulted object, the default constructor is used.

Rectangle(int w, int h) is a parameterized constructor that accepts two integer inputs to indicate the rectangle's width and height. It sets the supplied values as the initial values for the width and height data elements. When we create the paramRect object with dimensions 4 and 5, the parameterized constructor is called.

We call the calculateArea() member method to determine the rectangle's area after constructing the paramRect object and save the result in the area variable. The calculated area is then printed to the console.

The usage of constructors helps to guarantee that objects are correctly initialized and prepared for use at the time of creation. They are essential to object-oriented programming because they offer a mechanism to establish an object's initial state.

Destructor Functions:

A destructor is a particular member function of a class or struct in programming that is invoked whenever an object of that class is destroyed or exits its scope. Before an object is deleted from memory, resources that were allocated by it are cleaned up using destructors. They are the opposite of constructors, which set an object's state in motion.

A C++ example is provided below to demonstrate Destructor functions:


In this illustration, a class named Resource stands in for a resource that must be appropriately acquired and released. There are constructors and destructors for the class.

When an object of the Resource class is created, the constructor, specified as Resource(), is immediately called. In this instance, it prints "Resource acquired."

When an object is destroyed or leaves the scope of the application, the destructor, defined as Resource(), is immediately called. In this instance, it displays the text "Resource released."

We construct an object of the Resource class called a resource in the main method. The constructor is automatically invoked and prints the phrase "Resource acquired" when the object is constructed.

A nested object called nested resource is created within a code block. The message "Resource released" is written when the nested object exits the scope at the conclusion of the code block, and its destructor is automatically called.

The resource object finally leaves the scope after the main function completes, and its destructor is automatically executed, outputting the phrase "Resource released."

Prior to an object being destroyed, destructors are employed to carry out any necessary cleanup procedures, such as allocating dynamic memory, shutting files, or freeing up other resources. As a result, resource leaks are avoided and the program's general correctness is maintained. They make sure that the object's resources are appropriately handled and released.

Control Statement in CPP | Learn CPP Language |

 CONTROL STATEMENTS

Programming language constructs called control statements are used to manage how programs are executed. It enables the program to decide what to do and take different actions in response to certain circumstances. Control statements typically change the order in which statements are executed and allow for repeating or omitting some statements based on predefined circumstances.

Conditional, loop, and jump statements are the three primary categories of control statements in programming. A section of code is only executed using conditional statements if a specific condition is met. To repeatedly run a block of code, use loop statements. To move control to another area of the program, utilize jump statements.

Programming is not complete without control statements since they enable more responsive and dynamic code. They make it possible for programmers to create programs that can adjust to changing circumstances and run particular code depending on specified circumstances. Programmers can make their code more effective, readable, and upkeep-free by employing control statements.



What are the 3 types of control structures?

The sequence in which the statements are executed is known as control flow. The typical flow of a program is from top to bottom (sequential flow), but what if we want to only execute a certain block of code when a certain condition is met or run a block of code a certain number of times? These assertions will guarantee that a programme will move smoothly and purposefully.

Three categories of control statements exist:

1. Conditional/selection clauses

2. Loop/Iteration statements

3. statement jumps


1)Conditional/Selection statements

Statements that govern the flow of execution of a program based on specific circumstances are known as conditional or selection statements. If-else and switch-case are the two basic categories of conditional statements in C++.

  • Simple if-else: The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the C else statement. We can use the else statement with the if statement to execute a block of code when the condition is false. For example:-

In this example, we ask the user to enter a number and store it in the num variable. Then, we use an if-else statement to check if the number is even or odd. If the number is divisible by 2 (i.e., the remainder of the division is 0), then it's even, and we print a message saying so. Otherwise, we print a message saying that it's odd.

  • Else-if statement: The program first verifies the first condition (in the if statement) in an else-if statement. If the condition is met, the code block connected to the if statement is run before the entire if-else block is terminated. The following condition (in the else-if statement) is checked if the first condition is false before moving on to the next condition. If that circumstance holds true, the code block connected to the else-if statement is executed, and the entire if-else block is then terminated. If every condition is true, the programme runs the code block linked to the otherwise statement, if it is there.

The program in this illustration verifies the value of num. The first condition in the if statement is satisfied because num is bigger than 0, thus the programme performs the code block connected to that if statement (which outputs "num is positive"). The entire if-else section is then skipped by the programme. The programme would run the code block linked to the else-if expression (which outputs "num is negative") instead if num were a negative number. The programme would run the code block linked to the else statement (which outputs "num is zero") if num were zero.

  • Nestedif-else: If there are multiple nested if-else statements, only the first if statement will be performed. The code in the else block is run if the outer expression returns false. Here is an illustration of a C++ layered if-else statement:


In this example, the first if statement checks if the value of num is greater than 0. If it is, the inner if-else statement checks if num is even or odd. Since num is 15, it is not divisible by 2, and so the program outputs "num is odd".

  • Switch statement: The program initially evaluates the expression or variable included in brackets after the switch keyword in a switch-case statement. The value of that expression or variable is then contrasted with each of the scenarios given in the case statements. If a match is discovered, the programme runs the code block connected to that case statement before using the break statement to leave the switch block. In the absence of a match, the programme performs the code block linked to the default statement, if one exists. Here is an illustration of a C++ switch-case statement:

The program assesses the value of num in this case. The program runs the code block linked to the second case statement (which outputs "num is two") because num equals 2. The entire switch block is then terminated by the program. The code block related to the first case statement would be executed if the num were equal to 1. The program would run the code block connected to the third case statement if the num were equal to 3. The program would run the code block connected to the default statement if num had any other value.


2)Iteration/Loop statements:

As long as a specific condition is true, you can repeatedly run a block of code in C++ using iteration or loop statements. The while loop, the do-while loop, and the for loop are the three different forms of loops in C++.

  • while loop: The program initially assesses the condition enclosed in brackets before entering a while loop. The while loop's corresponding code block is run by the program if the condition is true. The procedure is then repeated; the condition is once more assessed, and if it is still true, the code block is once more executed. So long as the condition doesn't change, this will keep happening. Here's an example of a while loop in C++:


output:-


In this instance, the program sets the variable i to zero at the beginning. The while loop is then invoked, and the programme tests whether the condition i 5 is true. Since this condition is satisfied and i is currently 0, the while loop's code block (which outputs the value of i and subsequently increments i) is executed by the programme. The procedure is then repeated by the programme, which again assesses the condition (which is still true because i is now 1) and runs the code block. This continues up until i reaches a value of 5.

  • do-while loop: In a do-while loop, the code block corresponding to the loop is the first thing the program runs. After that, it assesses the parenthesized condition. The process is repeated if the condition is true: the code block is run once more, and the condition is once more evaluated. So long as the condition doesn't change, this will keep happening. Here's an example of a do-while loop in C++:


Output:



In this instance, the program sets the variable i to be initialized to 0. The code block for the do-while loop, which outputs the value of i and subsequently increments i, is then executed by the program. The program then assesses the i > 5 conditions. This condition is true because i is currently 1, so the program continues the procedure by running the code block once more and reevaluating the condition. This continues up until i reach a value of 5.

  • for loop:-  When you know how many times you want to iterate, you use a for loop. Initialization, a condition, and an increment or decrement make up its three components. As long as the condition remains true, the loop will keep running.

output:-


3)Jump statements

Jump statements allow us to move control between different parts of the programme. By skipping statements without any conditions given, these statements will change programme control. These are these claims:

1. Break

2. Continue

3. Pass

  • break statement:- Utilising the break statement, one can abruptly end a loop or switch statement. Control is passed to the statement that comes after the loop or switches when the break statement is encountered within one of those statements. Here is an example of using a break in a loop:


In this example, the loop will iterate from 0 to 9. However, when i equals 5, the break statement is executed, causing the loop to terminate prematurely.

  • continue statement: The continue statement is used to go on to the next iteration of a loop while skipping the current one. The remaining statements in the current iteration are skipped when the continue statement is met within a loop, and control is instead passed to the following iteration. Here is an example of using continue in a loop:


The loop will repeat from 0 to 9 times in this example. However, the continue statement is performed when i is an even integer (i.e., i% 2 == 0), leading the loop to skip the remaining statements in that iteration and move on to the following one.

  • goto statement: To move from one labeled statement inside the same function to another, use the goto statement. The labeled statement can come either before or after the goto statement and must be contained within the same function. Here is an illustration of how to use goto:


The program prints "Hello" constantly in an infinite loop in this example since the labelled statement is start: and the goto statement returns control to it.


so that's it for today Guys, follow us to learn more...

Keep Learning......

Learn CPP Programming | Data Tpes in CPP | CPP Roadmap

Data Types in C++

Overview

The first thing we must understand while beginning to learn any language is the Data type in order to begin using the language's coding features. The type of data that every variable could hold is known as the data type, and examples include character, float, and integer data types. Every language has a variety of data types, thus studying each type in depth can help us use them effectively and accurately.

Scope

In this post, we will learn about the definition of data types, their various subtypes, and the syntax for using them.
Here, we would also emphasize the types of data type modifiers.

Definition of Data Types

A data type is a classification or categorization of data in computer programming based on the type of value it holds. It instructs the computer on how to read and process data. Data types are crucial concepts in programming because they control how much memory is allocated to hold data and what operations may be performed on that data.

An integer data type, for example, can only carry whole integers, whereas a floating-point data type can only handle decimal numbers. A boolean data type can only store two values: true or false, whereas a string data type can store a string of characters.

Each programming language has its own set of data types, and each data type has its own set of rules and actions available to it. Programmers can guarantee that their programs are optimized for performance and accuracy by selecting the proper data type for a certain value.

To summarise, a data type is a method of categorizing data based on its value and the activities that may be performed on it. It is a crucial notion in programming since it allows programmers to design efficient and error-free code.

Examples include:


The variable value here is of the int datatype. Depending on the compiler, the variable score can only store 2 or 4-byte integers.

In C++, data types can be broadly categorized into three main categories:-

1)Built-in data types/primitive: Data types that are built into the C++ language and supported by the compiler are referred to as built-in data types. Integer, floating-point, character, boolean, void, and pointer types are among them.

2)User-defined data types: These are data types that the programmer creates using classes and structures.

3)Derived data types: These are data types derived from built-in data types or other derived data types. They include arrays, functions, and function pointers.


  • Built-in data types/primitive: Primitive data types are the fundamental data types incorporated into the C++ programming language and supported by the compiler. They are as follows:
    • integer types: The keyword int can be used to represent integer data types. A single integer takes up 4 bytes and has a range of -2147483648 to 2147483647. keywords-int, short, long, and long long. As an example:
    • Floating-point types: The keyword float is used to store floating-point numbers (decimals and exponentials). The float variable is 4 bytes in size. Keywordds-float, double, and long double.

    • Character type: Characters are represented by the keyword char. It is 1 byte long. In C++, single quotes'' are used to enclose characters. Keyword- char.

    • Boolean type: The boolean data type's keyword is bool. The boolean data type has two potential values: true or false. In general, Boolean values are utilized in conditional expressions and loops.

    • Void or Valueles: A void is something that has no value. The void data type describes an entity that has no value. It is not possible to declare variables of the void type. It is solely used for functions and does not return data.
    • Wide Character: The char data type is comparable to the wide-character wchar_t data type, except its size is 2 or 4 bytes rather than 1 byte. It is used to represent characters that require more memory than a single character.

Derived Data types in C++

These are data types that are descended from primitive data types or other descended data types. They include:

1) Function 

A function is a code segment or a piece of code that is defined to do a certain task. A function is frequently created to save the user from having to write the same lines of code for the same input multiple times. All of the code is integrated into a single function that may be called from anywhere. Every C++ application includes a function called main() by default. The function also includes a return type, which specifies the type of data that will be returned when the function's execution is complete. The function's return type can be any data type, including void, which indicates that there is no need to return anything once the function's execution is finished.


Here, the return type of the sum function is an integer, and the function is used to calculate the sum of 2 numbers.

2.Array

An array is a collection of elements that are retained in memory in a continuous fashion and contain the same sort of data. An array's goal is to store a large amount of data in a single variable name and sequential sequence.


Here, we have defined an integer array of size 4, which can continuously store four integer variables in memory.


3. Pointer 

Addresses are represented symbolically using pointers. Pointers hold the addresses of variables with the same datatype as the pointer. The pointer is either 4 bytes or 8 bytes in size, depending on the data type. They allow programs to generate and modify dynamic data structures, as well as emulate call-by-reference. Its generic declaration in C/C++ looks like this:


Sum holds the address of a variable of an integer datatype.

4. Reference

When we declare a variable as a reference, it becomes an alternate name for a variable that already exists. A variable can be declared as a reference by adding '&' to its declaration.


Here ref becomes the reference to integer val, and now any changes in one would be automatically reflected in the other as they both represent the same memory location.

Abstract or User-Defined Data Types in C++

The Abstract datatype, often known as the user-defined data type, is a type of data that the user defines. 

Examples of these are:

1)Class 

A Class is a component of C++ that leads to Object-Oriented programming. It is a custom data type with its own set of data members and member functions that can be accessed and utilized by creating a class instance. A class defines a data type's blueprint.


OUTPUT:-

1)Student name is: Ustola

2)Student name is: vegeta

In the above example, the student is the name of the class. We can include the data members, which are the class variables. Similarly, member functions are added to the class; for example, print(), here is the member function, and studentName is the data member. Here, st1 and st2 are the class student objects.


2)Structure

A structural datatype is a user-defined data type that mixes objects of potentially different data types into a single type.


In this case, several data types, such as an array of characters and integer data types, are joined to create a new data type based on the user's requirements.

3. Union

Union, like Structures, is used to combine several forms of data into a single user-defined data type. A union's members all have access to the same memory. In the example below, we may merge the integer and character data types into a single data type named test. In this situation, because the data sizes of the two data types, integer, and character, differ, we would utilize the larger data type as the size of the new user-defined data type test. If we modify mark, we can observe how changes in mark are reflected in var.


Here, mark and var share the same memory. Therefore, if we change any variables, the changes will automatically reflect in another variable.

4. Enumeration

An enumeration (or enum) is a data type that the user constructs in C++. It's mostly used to give integral constant names, which makes the program easier to understand and maintain. If we do not explicitly provide the integral values to the strings in enumeration, the strings will start assigning the integral values from value 0, just like in the case of 0-based indexing.


If we were given the integer value 100 to be pass and 0 as fail: if we write,


Then, the value of res would automatically be 100.

5. Typedef defined DataType

In C++, you can specify explicit new data type names using the phrase typedef. Instead of creating a new data class, typedef names an existing one. Because just the typedef declarations would need to be modified, the portability of a program might be increased by making only minor modifications. Typedef can help with self-documentation by allowing descriptive terms for standard data types.

for example:-

Now we can use longl to define the long int data type in the code.


Datatype Modifiers in C++

DataType modifiers can be used to further modify some of the core data types. There are four modifiers in C++. These modifiers can be applied to data types such as int, double, and char. They are as follows:-

1. signed

2. Unsigned

3. short

4. Long



Conclusion

Datatypes are the first thing we need to learn when learning a programming language. In this session, we learned a lot about data types, and I recommend that you practice with data types more if you want to master C++ quickly. As a result of reading the preceding article, here are some key takeaways:

1. C++ has three data types: primitive data types, abstract data types, and derived data types.

2. Primitive data types include integers, floating points, characters, Booleans, double floating points, valueless or void, and wide characters.

3. Array, function, pointer, and reference are examples of derived data types.

4. Short, long, signed, and unsigned data modifiers can be applied to data types such as int, double, char, and so on.