Document

What is C++?


Why should we learn C++/ Features of C++?


How is it different from C?


Basic Structure & Syntax

Programming in C++ involves following a basic structure throughout. To understand that basic structure, the first program we learned writing in C++ will be referred to.

C++ Data Types & Constants


C++ Data Types

Data types define the type of data a variable can hold; for example, an integer variable can hold integer data, a character can hold character data, etc.
Data types in C++ are categorized into three groups:

Built-in data types

These data types are pre-defined for a language and could be used directly by the programmer.
Examples are: Int, Float, Char, Double, Boolean

User-defined data types

These data types are defined by the user itself.
Examples are: Class, Struct, Union, Enum

Derived data types

These data types are derived from the primitive built-in data types.
Examples are: Array, Pointer, Function


Some of the popular built-in data types and their applications are:

C++ Constants

Constants are unchangeable; when a constant variable is initialized in a program, its value cannot be changed afterwards.

OUTPUT:

C++ Operators

Special symbols that are used to perform actions or operations are known as operators. They could be both unary or binary.
For example, the symbol + is used to perform addition in C++ when put in between two numbers, so it is a binary operator. There are different types of operators. They are as follows:


Arithmetic Operators

Relational Operators

Logical Operators

Bitwise Operators

Assignment Operators

Functions

Functions are the main part of top-down structured programming. We break the code into small pieces and make functions of that code. Functions could be called multiple or several times to provide reusability and modularity to the C++ program.

Functions are also called procedures or subroutines or methods and they are often defined to perform a specific task. And that makes functions a group of code put together and given a name that can be called anytime without writing the whole code again and again in a program.

Advantages of Functions

Types of functions


Library functions:

Library functions are pre-defined functions in C++ Language. These are the functions that are included in C++ header files prior to any other part of the code in order to be used.
E.g. sqrt(), abs(), etc.

User-defined functions:

User-defined functions are functions created by the programmer for the reduction of the complexity of a program. Rather, these are functions that the user creates as per the requirements of a program.
E.g. Any function created by the programmer.


Example of a function for swapping two numbers:


Output:

Document
PROCODING
Copyright © 2023 to Rohit Negi