C++ 2 Sem PPT 1
C++ 2 Sem PPT 1
PROGRAMMING
• C++ is the most used and most popular programming language
developed by Bjarne Stroustrup. C++ is a high-level and object-
oriented programming language
There is no access specifier in procedural Object-oriented programming has access specifiers like
programming. private, public, protected, etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper Object-oriented programming provides data hiding so
way of hiding data so it is less secure. it is more secure.
concept of objects. Objects contain data in the form of attributes and code in the form of methods. In
object-oriented programming, computer programs are designed using the concept of objects that
interact with the real world. Object-oriented programming languages are various but the most popular
ones are class-based, meaning that objects are instances of classes, which also determine their types.
• Compiler Based
• C++ is a compiler-based language, unlike Python. That is C++ programs used to
be compiled and their executable file is used to run them. C++ is a relatively
faster language than Java and Python.
• Dynamic Memory Allocation
• When the program executes in C++ then the variables are allocated the
dynamical heap space. Inside the functions, the variables are allocated in the
stack space. Many times, We are not aware in advance how much memory is
needed to store particular information in a defined variable and the size of
required memory can be determined at run time.
C C++
• Applications of C++:
C++ finds varied usage in applications such as:
• Operating Systems & Systems Programming. e.g. Linux-based OS (Ubuntu etc.)
• Browsers (Chrome & Firefox)
• Graphics & Game engines (Photoshop, Blender, Unreal-Engine)
• Database Engines (MySQL, MongoDB, Redis etc.)
• Cloud/Distributed Systems
1st C++ program
Line 1: "#include<iostream>" - this
whole text is called a header file.
iostream" is the name of a library,
added to our program.
The iostream library helps us to get
input data and show output data.
std::cout<<" hello world";' - In this
line of code "std" is a namespace, "::"
is the scope resolution operator and
"cout<<" is a function which is used
to output data, "hello world“
<<- Insertion operator or put to
operator
Procedural oriented programming
Problem: As we have global data in POP , the transfer of data is more in
POP. Due to transfer of data the data becomes less secure. Any function
can update global data
OBJECT ORIENTED PROGRAMMING
CLASS
The building block of C++ that leads to Object-Oriented programming is a Class. It is a user-
defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class
• For Example: Consider the Class of Cars. There may be many cars with different names and
brands but all of them will share some common properties like all of them will have 4 wheels,
Speed Limit, Mileage range, etc. So here, the Car is the class, and wheels, speed limits, and
mileage are their properties.
• example of class Car, the data member will be speed limit, mileage, etc and member
functions can apply brakes, increase speed, etc.
Object
• An Object is an identifiable entity with some characteristics and behavior. An
Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instantiated (i.e. an object is created) memory is
allocated.
Encapsulation
• The word “polymorphism” means having many forms. In simple words, we can
define polymorphism as the ability of a message to be displayed in more than
one form.
• Types of Polymorphism:
• Compile-time Polymorphism
• Runtime Polymorphism
Inheritance
1. Primitive Data Types: These data types are built-in or predefined data types
and can be used directly by the user to declare variables. example: int, char, float,
bool, etc. Primitive data types available in C++ are:
• Integer
• Character
• Boolean
• Floating Point
• Double Floating Point
• Valueless or Void
• Wide Character
2. Derived Data Types: Derived data types that are derived from the primitive or
built-in datatypes are referred to as Derived Data Types. These can be of four types
namely:
• Function
• Array
• Pointer
• Reference
3. Abstract or User-Defined Data Types: Abstract or User-Defined data types are
defined by the user itself. Like, defining a class in C++ or a structure. C++ provides the
following user-defined datatypes:
• Class
• Structure
• Union
• Enumeration
• Typedef defined Datatype
void
• Uses of void:
• To specify the return type of function which is not returning anything
• to indicate empty list to a function . Eg-Void func19(void);
• Another intresting use of void is to create generic pointer eg- void *gp;
Cout
• The cout object in C++ is an object of class iostream. It is defined in iostream header file.
It is used to display the output to the standard output device i.e. monitor. It is associated
with the standard C output stream stdout. The data needed to be displayed on the
screen is inserted in the standard output stream (cout) using the insertion operator(<<).
#include <iostream>
using namespace std;
// Driver Code
int main()
{
// Print standard output
// on the screen
cout << "Welcome to GFG";
return 0;
}
Cin
• The cin object in C++ is an object of class iostream. It is used to accept the input from the standard input device i.e. keyboard. It is
associated with the standard C input stream stdin. The extraction operator(>>) is used along with the object cin for reading
inputs. The extraction operator (>>)extracts the data from the object cin which is entered using the keyboard.
#include <iostream>
using namespace std;
// Driver Code
int main()
{
string s;
#include <iostream>
using namespace std;
int main( ) {
cout << "C++ Tutorial";
cout << " Javatpoint"<<endl;
cout << "End of line"<<endl;
}
C++ Identifiers
• Constants
• Variables
• Functions
• Labels
• Defined data types
A keyword is a reserved word. You cannot use it as a variable name, constant name
etc.
A list of 32 Keywords in C++ Language which are also available in C language
are given below.
auto break case char const conti defau do
nue lt
doubl else enum exter float for goto if
e n
int long regist retur short signe sizeof static
er n d
struct switc typed union unsig void volati while
h ef ned le
asm dynamic_c namespace reinterpret_ bool
ast cast
A list of 30 Keywords in C++
explicit new static_cast false catch
Language which are not
available in C language are operator template friend private class
given below. this inline public throw const_cast
delete mutable protected true try
typeid typename using virtual wchar_t
Storage class in C++
Symbolic constant
• There are two ways of carting symbolic constants:
1) Using the qualifier const
2) Defining a set of integer constant using enum keyword
Eg – const int size= 10;
Char name[size];
Declaration of variables